arxiv_id
stringlengths
0
16
text
stringlengths
10
1.65M
\documentclass{report} \title{\textsc{A Digital Signal Processing Report on \\ \Huge Image Steganography using LSB Matching}} \author{\\\\ {\bf \underline{Member Details}} \\\\{\bf MEMBER-1: Himanshu Sharma} \\ {\bf Roll Number: $1610110149$} \\ {\bf Dept. of Electrical Engineering (ECE)} \\\\{\bf MEMBER-2: Mridul Agarwal} \\ {\bf Roll Number: $1610110199$} \\ {\bf Dept. of Electrical Engineering (EEE)} \\\\ {\bf MEMBER-3: Vedansh Gupta} \\ {\bf Roll Number: $1610110429$} \\ {\bf Dept. of Electrical Engineering (ECE)}\\\\\\\\ {\bf Shiv Nadar University,} \\ {\bf Gautam Buddh Nagar, Greater Noida, Uttar Pradesh 201314} \\\\\\ \textsc{ Under the guidance of Professor Vijay K. Chakka}} \date{} \usepackage[margin=0.8in]{geometry} \usepackage{graphicx} \usepackage{float} \usepackage{amsmath} \usepackage{algorithm} \usepackage[noend]{algpseudocode} \usepackage{fourier-orns} \usepackage{csquotes} \newenvironment{ppl}{\fontfamily{pcr}\selectfont}{\par} \begin{document} \maketitle \pagenumbering{gobble} \renewcommand{\thesection}{\arabic{section}} % include the paper here. \section{Paper Comprehension by Member 1 - Himanshu Sharma} {\it Image Steganography} is the art of hiding information inside a digital image. Steagnography does not restrict to only plain text but it includes text, video, audio and image hiding also. In this report, the author has restricted himself to text data type only. Even when doing text embedding, there are immense possible algorithms to choose from. The most popular among them is the LSB replacement or Least Significant Bit replacement. With this type of algorithm, the least significant bit of each pixel (only one channel out of the RGB pallete) is changed by a bit decided according to the message bit. Therefore, we should not expect much change in the image after data hiding because the least significant bit is changed. For example, lets take a blue channel with value of 145. In binary, it is equivalent of 10010001. If by some technique, the last bit is changed to 0, then the decimal equivalent would become 144, which does not change the image much. This is the power of LSB replacement. It basically relies on the fact that hiding message bits in the LSB of each pixel does not affect the image much, in fact, the image practically remains as it is. There are, however, techniques now in modern signal processing science which can detect that some data is hidden in the image or not, a field called {\it steganalysis}. A successful hiding algorithm would be that, that would allow high payload and still look similar to the original image. \subsection{LSB Matching} In LSB matching, if the message bit does not match with the pixel's LSB, then $\pm 1$ is randomly added to that pixel value. Unlike LSB replacement, where the pixel's LSB is just replaced by the message bit, here, a set of conditions are used to modify the pixel. LSB Matching could not be detected using the techniques used to detect LSB replacement. However, now it has been proved that LSB matching acts like a low pass filter on the digital images and therefore, this fact is utilized to detect whether LSB matching is applied on an image or not. \par Usually, two consecutive pixels are taken alongwith two consecutive message bits. The consecutive pairs are chosen randomly based on the {\it pseudo-random number generator} (PRNG). If the LSB matching is used as it is, then any pixel could be chosen with every pixel pair having equal chances of being selected by the algorithm. This has a flaw. This type of approach makes it difficult to disguise a changed pixel to the pixel surrounding it. For example, if lot of pixels are changed in a close vicinity, then they could be easily identified if the region is light in color, like sky which is light blue in color. The paper chosen here tries to rectify this problem by chosing those pixels on the image which lie on the edges. Edges are usually sharper than the surrounding regions and therefore its not easy to identify the change in pixel color on the edges. Similar papers have already been published. All of them suggest to use what is called the {\it pixel-value difference} (PVD). \par In PVD, what we do is that when we try to hide a message bit in a pixel's LSB, the pixel value is compared with its neighbouring pixels. If the difference is large, then more bits can be accomodated in that region without them being easily identified. Why? Because if there is a large difference in the pixel values then on changing the pixel value will not generate any significant difference. For example, if a pixel that is to be modified has a value of 45 and it's neighbouring pixel has a value of 145, then the difference $\displaystyle \Delta = 145-45=100$. Now, if by some technique if this pixel value if changed to 46, then the difference would become $\displaystyle \Delta' = 145-46 = 99$. To a human eye, this difference is not accountable. PVD is a good approach, in fact, far more better that PRNG because it utilizes the fact that sharp changes can be used to hide the information. \par In both LSB replacement and LSB matching, a travelling order is generated using PRNG which also acts as a key for decoding the stego-image. In both of these algorithms, the LSB of the selected pixel becomes equal to the message bit. According to the algorithm, if the two consecutive pixels are $x_{i}$ and $x_{i+1}$ and the consecutive message bits are $m_{i}$ and $m_{i+1}$, then the pixels are modified such that $x_{i}$ becomes $x_{i}^{'}$ and $x_{i+1}$ becomes $x_{i+1}^{'}$ and the following relation holds. \begin{center} $ \displaystyle LSB(x_{i}^{'})=m_{i} \textrm{ and } LSB \Big( \Big\lfloor{\frac{x_{i}^{'}}{2}}\Big \rfloor + x_{i+1}^{'} \Big) = m_{i+1}$ \end{center} From experiments done by the authors of the paper it has been shown that even if the cover image has rough textures, it will still have smooth regions in every $5 \times 5$ non-overlapping blocks. So, if by any chance, a pixel is selected in that region for message hiding then it could be easily identified. This is what the paper aims to solve. \subsection{Bit Planes} We now come to a brief discussion on what is called the bit planes. Bit planes help us visualize the importance of the significant bits used to represent the images. They clearly display the fact that altering the LSB of pixels is less damaging to the original image than altering the MSB of the same original image. Before we discuss them in great detail, let me show an example. Suppose we have a cover image which is shown below. \begin{figure}[H] \centering \includegraphics[width=0.5\textwidth]{images/desktop.jpg} \caption{Cover Image} \end{figure} Its bit planes are shown below. The LSB plane and the MSB planes are what we display first. \begin{figure}[H] \centering \begin{minipage}{0.46\linewidth} \includegraphics[width=\textwidth]{images/plane1.png} \caption{MSB Plane} \end{minipage} \hfill \begin{minipage}{0.46\linewidth} \includegraphics[width=\textwidth]{images/plane8.png} \caption{LSB Plane} \end{minipage} \end{figure} Changing a pixel value in the MSB plane is more prone to human eye detection as compared to the LSB plane. This is because a MSB plane has more structured black and white regions, and so, changing any pixel value, for example say, that a pixel is changed from white to black in the white region, then it would be easily detected. Whereas, on a LSB plane, the black and white regions are more uniformly aligned, just like {\it white noise} on a television screen. Inverting any color on the LSB plane won't change the visual effect. Hence, it is always advised to change the LSB plane in stegnography. \par The idea is to generate these images using single values. Since we have 3 values associated with a single pixel {\it (R, G, B)}, it would be a great idea to convert the image to a grayscale image, so that each pixel is represented by a single value. Now each pixel value, which initially was a three dimensional array, is converted to a one dimensional array having a single value. This matrix of single values (grayscale image) is passed to a function which converts these decimal pixel values to 8 bit binary number. As per the request of the user, the $i^{th}$ bit from each binary pixel is accessed. So, for example, if a pixel has 8-bit binary representation as 11110101 and the user asks for fifth bit plane, then the fifth bit from starting would be accessed and that is 0 for this example. These values are stored in another matrix. So now we have a matrix with only 1 and 0s. We now multiply each and every value of the matrix by 255. The matrix becomes full of 255 and 0s. Zero represent black color and 255 represent white color. When saved, this image is a black and white $i^{th}$ bit plane. \par Below, I have shown all the bit planes of the above cover image. \begin{figure}[H] \centering \begin{minipage}{0.46\linewidth} \includegraphics[width=\textwidth]{images/1.png} \caption{$1^{st}$ bit plane or the MSB Plane} \end{minipage} \hfill \begin{minipage}{0.46\linewidth} \includegraphics[width=\textwidth]{images/2.png} \caption{$2^{nd}$ bit plane} \end{minipage} \vfill \begin{minipage}{0.46\linewidth} \includegraphics[width=\textwidth]{images/3.png} \caption{$3^{rd}$ bit plane} \end{minipage} \hfill \begin{minipage}{0.46\linewidth} \includegraphics[width=\textwidth]{images/4.png} \caption{$4^{th}$ bit plane} \end{minipage} \hfill \begin{minipage}{0.46\linewidth} \includegraphics[width=\textwidth]{images/5.png} \caption{$5^{th}$ bit plane} \end{minipage} \hfill \begin{minipage}{0.46\linewidth} \includegraphics[width=\textwidth]{images/6.png} \caption{$6^{th}$ bit plane} \end{minipage} \hfill \begin{minipage}{0.46\linewidth} \includegraphics[width=\textwidth]{images/7.png} \caption{$7^{th}$ bit plane} \end{minipage} \hfill \begin{minipage}{0.46\linewidth} \includegraphics[width=\textwidth]{images/8.png} \caption{$8^{th}$ bit plane or the LSB plane} \end{minipage} \end{figure} Clearly, as we increase the bit plane number, we are bound to get more better results. Increasing the bit plane number implies less human eye detection in case of a pixel change. Now let us see the mathematical reasoning behind the bit planes. \newpage Let us define a closed form expression which converts a binary number to its decimal equivalent. \begin{equation} \displaystyle d(n) =\sum_{i=1}^{n}g(n+1-i,\textrm{ } b)2^{n-i} \end{equation} where $g(k, b)$ returns the $k^{th}$ bit from left of the binary number $b$ and $n$ denotes the length of the binary number. Here we are dealing with $n=8$. Let us say that the $j^{th}$ bit is changed while doing some steganography. The $j^{th}$ bit could be LSB or MSB or any other bit in between, we are not concerned about that for now. So, we know that $ 1 \leq j \leq n$. Let the original binary number be $\alpha$ and the binary number after the changed bit be denoted by $\beta$. Hence we get, \begin{center} $\displaystyle d_{1}(n) =\sum_{i=1}^{n}g(n+1-i,\textrm{ } \alpha)2^{n-i}$ and $\displaystyle d_{2}(n) =\sum_{i=1}^{n}g(n+1-i,\textrm{ } \beta)2^{n-i}$ \end{center} If we take the difference $\Delta d(n) = (d_{1} - d_{2})(n)$, the we get, \begin{equation} \displaystyle \Delta d(n) =\sum_{i=1}^{n}g(n+1-i,\textrm{ } \alpha)2^{n-i} - \sum_{i=1}^{n}g(n+1-i,\textrm{ } \beta)2^{n-i} \end{equation} Assuming all other bits of $\alpha$ and $\beta$ to be same except for the $j^{th}$ bit, we get, \begin{center} $\displaystyle \Delta d(n) = g(n+1-j, \alpha)2^{n-j} - g(n+1-j, \beta)2^{n-j} = 2^{n-j} \Delta g(n, j)$ \end{center} where, $\Delta g(n, j) = g(n+1-j, \alpha) - g(n+1-j, \beta)$ and thus we get, \begin{equation} \displaystyle \delta (n) = |\Delta d(n)| = 2^{n-j}|g(n, j)| \end{equation} Note that $\Delta d(n)$ is the difference in the decimal values of the binary numbers which can be positive, negative or 0, $\delta (n)$ is always non-negative. Now, $|\Delta g(n, j)|$ can be defined as follows; \[ |\Delta g(n, j)| = \begin{cases} 1, & j^{th} \text{ bit of $\alpha$ and $\beta$ are different} \\ 0, & \text{otherwise} \end{cases} \] The {\it otherwise} case is trivial because if there is no difference in even the $j^{th}$ bit of these binary numbers, then both of them are identical. This means that the number was not changed. But if the number has change, then $|\Delta g(n, j)|$, for sure, is 1. Now, it is in this part we are concerned with the difference. We need to minimize this difference $\delta(n)$ because then only our stego-image will be statistically close to the original image. The value of $\delta(n)$ could be minimum only if $n=j$ (see equation 3), i.e., $\delta(n) = |\Delta g(n, j)|$ which is 1 if we assume that the pixel bit was changed. That is, the difference in decimal value has the minimum magnitude of 1, 0 being the trivial case that the binary numbers were never changed. Since the decimal difference value will decide the grayscale of the stego-image, we want to minimize it. This proves that if we want statistically similar features in the stego-image, we should take $j=n$, i.e., we should consider the LSB only, because that would affect the orignal decimal value by $\pm 1$ only. \par If we do consider $j=1$, then $\delta(n) = 2^{n-1} |\Delta g(n, 1)|$. Again, $\Delta g(n, 1) = \pm 1$ if we consider that the pixel value was changed. However, it is clear that $2^{n-1}$ will yield the maximum difference, and therefore, $j=1$ should never be taken, or, MSB should never be changed. \subsection{The Algorithm} The paper provides a scheme to optimize the traditional LSB algorithm. It covers an extra mile by embedding the key information in the stego-image itself. We can also say that first the pixels are changed according to the algorithm and then the key information is embedded into the image. Finally, the image thus obtained is the stego-image. \par Let me now explain how the data embedding is done in the image. \newpage \underline{\large Data Embedding} \\ \par Data embedding in the image starts by a new process which is generally not found in traditional steganography algorithms. First the image is divided into non-overlapping blocks of size $B \times B$ (as per the paper). Then we rotate each and every individual block by some random angle $\theta$, where $\theta \in \{0, 90, 180, 270\}$ in degrees. \par Dividing the image into non-overlapping blocks and then rotating each block by a random angle increases the security. That is because if we rotate the image before we embedd message bits in it and then later on rotate back those blocks to form the cover-like image, we have actually gained a great deal of security as compared to the image on which the embedding was done directly. Think about it, since the image is rotated back after embedding, all the embedded bits have been shuffled. Now, if some attacker tries to bruteforce, then even if he guesses the correct key, he won't be able to get the correct message. \par Now, the image is raster scanned. Raster scan is like converting an image into a row vector. In language like Python which I am using, this transformation can be achieved by using the statement \texttt{img.flatten()}, where \texttt{img} is the image as a numpy array. To read about numpy, please visit the docs. After this step, consecutive pixels are selected in pairs and following set is defined. \begin{equation} S(t) = \{(x_{i}, x_{i+1})| |x_{i} - x_{i+1}| \geq t, \forall (x_{i}, x_{i+1}) \in V \} \end{equation} where $V$ is the raster scanned image and $t$ is some value in the set $\{0, 1, 2, ..., 31 \}$. In other words, $S(t)$ is the set of all those consecutive pixels in the raster scanned image which have a differece greater than or equal to the parameter $t$. After this, the threshold value $T$ is calculated by the following method. \begin{equation} T = \textrm{argmax}_{t}\{2 \times n(S(t)) \geq n(M)\} \end{equation} where, $n(S)$ denotes the number of elements in $S$ and $M$ is the message. This equation, that is, equation 5 checks whether the message bits can be embedded in the image or not. Now let us understand what this equation actually means. Suppose a hypothetical case of $S(t) = \{ (x_{1}, x_{2}), (x_{3}, x_{4}), (x_{5}, x_{6}) \}$ for some $t=t_{1}$ and let $M$ be a 5 bit stream. Then, we find that $2 \times 3 \geq 5$ where $n(S(t)) = 3$. We chose some other $t$ now which is $t=t_{2} > t_{1}$. For this, let us say that we get $n(S(t)) = 2$, impling $2 \times 2 \geq 5$ which is false and therefore $T=t_{1}$. This is what equation 5 tries to say. It gives us that maximum $t$ for which the condition in the equaiton holds true. It is clear why we are multiplying by $2$. Thats because each pixel can hold one bit from the message stream and $S$ contains a tuple of such pixels. In total, we have twice the length pixels. A good observation is that if $T=0 \textrm{ }\exists \textrm{ }t$, then that would mean that our equation 5 is satisfied only for max $t=0$. Hence, our equation 4 would become, \begin{center} $ S(0) = \{(x_{i}, x_{i+1})| |x_{i} - x_{i+1}| \geq 0, \forall (x_{i}, x_{i+1}) \in V \} $ \end{center} This is what a conventional LSB steganography technique does. It just embedds the message stream without thinking about the difference between the consecutive pixels. \par We now come to the discusssion of the main pseudocode which actually embedds the data in the image. Below, I have shown the algorithm used for LSB matching. \begin{algorithm} \caption{LSB Matching}\label{euclid} \begin{algorithmic}[1] \Procedure{hide}{} \If {$LSB(x_{i}) = m_{i}$} \If {$f(x_{i}, x_{i+1})=m_{i+1}$} \State $(x_{i}^{'}, x_{i+1}^{'}) = (x_{i}, x_{i+1})$ \Else \State $(x_{i}^{'}, x_{i+1}^{'}) = (x_{i}, x_{i+1}+r)$ \EndIf \EndIf \If {$LSB(x_{i})\neq m_{i}$} \If {$f(x_{i}-1, x_{i+1})=m_{i+1}$} \State $(x_{i}^{'}, x_{i+1}^{'}) = (x_{i}-1, x_{i+1})$ \Else \State $(x_{i}^{'}, x_{i+1}^{'}) = (x_{i}+1, x_{i+1})$ \EndIf \EndIf \EndProcedure \end{algorithmic} \end{algorithm} \\ This algorithm is used for hiding the text data inside the image. $r$ is any random value in $\{ 1, -1\}$. Where, $(x_{i}^{'}, x_{i+1}^{'})$ are the new pixel values after data hiding. After this, the image blocks are rotated back to get the orignal image like image back and the angle values, the threshold $T$ and the block size are bundled into a binary file and returned as the key, back to the user. \newpage \underline{\large Data Extraction} \\ \par Now, to get back the message stream, the image is first divided into blocks of size $B \times B$ again and then each of these blocks is rotated by the angles provided in the key file. Then those pixels are found in which data hiding was actually done using the inequality $|x_{i+1}-x_{i}|\geq T$. Now, to get back two units of the stream, the formula given in section 1.1 is used (refer section 1.1). \subsection{Conclusions} In the case of data embedding, the lower the value of $T$, more number of bits from the message can be embedded in the cover image. The following reasoning proves this; if we have two thresholds $T_{1}$ and $T_{2}$ with $T_{1} < T_{2}$, then this would mean \begin{center} $\textrm{argmax}_{t}\{2 \times n(S_{1}(t)) \geq n(M)\} < \textrm{argmax}_{t}\{2 \times n(S_{2}(t)) \geq n(M)\}$ \end{center} where, \begin{center} $ S_{1}(t) = \{ (x_{i}, x_{i+1})||x_{i} - x_{i+1}| > t_{1}, \forall (x_{i}, x_{i+1}) \in V\} $ \\ $ S_{2}(t) = \{ (x_{i}, x_{i+1})||x_{i} - x_{i+1}| > t_{2}, \forall (x_{i}, x_{i+1}) \in V\} $ \end{center} Because $T_{1} < T_{2} \implies t_{1} < t_{2}$ and that would mean that $S_{1}$ has lesser threshold value when compared to $S_{2}$. This would mean that more pixels would be available which satisfies $|x_{i} - x_{i+1}| > t_{1}$ than the pixels which satisfy $|x_{i} - x_{i+1}| > t_{2}$. Hence, $S_{1}$ would contain more elements or tuples than $S_{2}$. This is what the very first statement is saying, that if, threshold is small, more pixels could be accomodated. \par With steganography in mind, in general, we always need to compare the images for steganalysis. For this we first calculate the {\it mean square error} (MSE) between the cover $(A)$ and the stego-image $(B)$ by the following relation, \begin{equation} MSE(A, B) = \frac{1}{N} \sum_{i=0}^{N} (A_{i} - B_{i})^{2} \end{equation} Where, the subscript $i$ denotes the $i^{th}$ pixel of the image. Here, actually, the MSE is the noise introduced in the cover image after steganography has been performed on it. So, in decibels (dB), the Peak Signal to Noise Ratio (PSNR) is given by, \begin{equation} PSNR_{dB} = 10 \log_{10}\Bigg|\frac{max^{2}(A)}{MSE}\Bigg| \end{equation} Where $max(A)$ is the maximum pixel value in the image or the peak signal available in the image. \par The techinque used in this paper produces exactly identical image after doing steganography as was the original cover image. Below, I have shown the eighth bit plane of a cover image and its stego-image as an example. \begin{figure}[H] \centering \begin{minipage}{0.46\linewidth} \includegraphics[width=\textwidth]{images/konsole.png} \caption{Cover Image LSB plane} \end{minipage} \hfill \begin{minipage}{0.46\linewidth} \includegraphics[width=\textwidth]{images/konsole-stego.png} \caption{Stego Image LSB plane} \end{minipage} \end{figure} Clearly, we see that both the bit planes are identical looking, although they are not in exact sense. If the planes are zoomed and then viewed, then it is easy to spot differences. These differences occur because of resizing done by the code and some due to the embedded text also. Since there is such an uniformity in the LSB planes of both cover and stego-image, its practically impossible for someone to spot the difference in the cover and stego-image. I thus conclude by saying that image steganography is successfully implemented by me. \underline{Full code base is written in Python and is available on my GitHub repository at} \begin{center} {\bf https://github.com/hmnhGeek/DSP-Project-Report-LaTeX} \end{center} This report is also available with it's complete \LaTeX code in the same repository under the \texttt{Report} folder. I would like the reader to surely go through the repository once. \\ \par {\bf My contributions include the following,} \begin{enumerate} \item Full code base in Python dedicated to this project. \item Report writing done with \LaTeX. \end{enumerate} \section{Paper Comprehension by Member 2 - Mridul Agarwal} The science which deals with the hidden communication is called steganography whereras steganlaysis aims to detect the presence of hidden secret message in the stego media. There are different kinds of steganographic techniques which are complex and which have strong and weak points in hiding the information in various file formats. The file format used in this paper is images. The images which are used to hide the message $(M)$ are called cover images whereas the altered (steganographed) images are called stegos. The message hidden here is a binary stream. \par A steganography method is secure only when the statistics of the cover image and the stego are similar to each other. Image steganography is of two types-lossy compression and lossless compression. Lossy compression may not preserve the original image where as lossless compression preserves the original image. Examples of lossless compression formats are GIF,BMP,PNG etc. and that of lossy compression are JPEG. Also embedding capacity is also an important factor in designing a steganographic algorithm. \par Most of the existing steganographic techniques, the choice of embedding positions within a cover image mainly depends on a pseudorandom number generator (PRNG) without considering the relationship between the image content itself and the size of the secret message. Here the researchers have extended the LSB matching revisited (LSBMR) image steganography and propose an edge adaptive scheme which can select the embedding regions according to the size of secret message and the difference between two consecutive pixels in the cover image. \subsection{LSB Replacement} In this embedding technique, only the LSB of the cover image pixel is overwritten with the secret bit stream according to a pseudorandom number generator (PRNG). As a result, some structural asymmetry is introduced, and thus it is very easy to detect the existence of hidden message even at a low embedding rate. \subsection{LSB Matching (LSBM)} LSB matching (LSBM) employs a minor modification to LSB replacement. If the secret bit does not match the LSB of the cover image, then $\pm 1$ is randomly added to the corresponding pixel value. Statistically, the probability of increasing or decreasing for each modified pixel value is the same and so the obvious asymmetry introduced by LSB replacement can be easily avoided. Therefore, the common approaches used to detect LSB replacement are totally ineffective at detecting the LSBM. \subsection{LSB Matching Revisited} Unlike LSB replacement and LSBM, which deal with the pixel values independently, LSB matching revisited (LSBMR) uses a pair of pixels as an embedding unit, in which the LSB of the first pixel carries one bit of secret message, and the relationship (odd–even combination) of the two pixel values carries another bit of secret message. \par The regions located at the sharper edges present more complicated statistical features and are highly dependent on the image contents. It is more difficult to observe changes at the sharper edges than those in smooth regions. \newpage LSBMR applies a pixel pair $(x_{i}, x_{i+1})$ in the cover image as an embedding unit. After message embedding, the unit is modified as $(x_{i}^{'}, x_{i+1}^{'})$ in stego image which satisfies, \begin{center} $ \displaystyle LSB(x_{i}^{'})=m_{i} \textrm{ and } LSB \Big( \Big\lfloor{\frac{x_{i}^{'}}{2}}\Big \rfloor + x_{i+1}^{'} \Big) = m_{i+1}$ \end{center} By using the relationship (odd–even combination) of adjacent pixels, the modification rate of pixels in LSBMR would decrease compared with LSB replacement and LSBM at the same embedding rate. It also does not introduce the LSB replacement style asymmetry. Similarly, in data extraction, it first generates a traveling order by a PRNG with a shared key. And then for each embedding unit along the order, two bits can be extracted. The first secret bit is the LSB of the first pixel value, and the second bit can be obtained by calculating the relationship between the two pixels given by above formula. Our human vision is sensitive to slight changes in the smooth regions, while it can tolerate more severe changes in the edge regions. This proposed scheme will first embed the secret bits into edge regions as far as possible while keeping other smooth regions as they are. \subsection{Proposed Idea} The flow diagram of proposed scheme is illustrated in figure below. In the data embedding stage, the scheme first initializes some parameters, which are used for data pre-processing and region selection, and then estimatesthe capacity of those selected regions. If the regions are large enough for hiding the given secret message , then data hiding is performed on the selected regions. Finally, it does some postprocessing to obtain the stego image. Otherwise the scheme needs to redo the parameters, and then repeats region selection and capacity estimation until can be embedded completely. \begin{figure}[H] \centering \includegraphics[width=0.6\textwidth]{images/proposed_scheme.png} \caption{Proposed Scheme (as given in the paper)} \end{figure} They use the absolute difference between two adjacent pixels as the criterion for region selection, and use LSBMR as the data hiding algorithm. \par The {\bf step 1} of the algorithm mainly first divides the whole image into nonoverlapping blocks of $B_{z}\times B_{z}$ pixels and then rotates each block by $\{0,90,180,270\}$ as determined by a secret key.The resultant image is reshaped into an row vector which is then divided into non overlapping embedding units (two consecutive pixels). \par {\bf Step 2} calculates the threshold $T$ for region selection using given formula. \par {\bf Step 3} Implements data hiding according to four discussed cases.If the modifications are out of constraints then they are readjusted. \par {\bf Step 4} is similar to step 1 except that the blocks are rotated by same degrees but in opposite direction. The parameters for $(T,B_{z})$ are hidden in a preset area. \par {\bf Analysis} - One of the important properties of this steganographic method is that it can first choose the sharper edge regions for data hiding according to the size of the secret message by adjusting a threshold $T$. The experimental results are summarized in table-3 for different embedding rates in the paper itself, show that it has the minimum accuracy of being detected in most of the cases amongst the seven steganographic algorithms. \newpage \section{Paper Comprehension by Member 3 - Vedansh Gupta} In this paper, we expand the LSB matching revisited image steganography propose an edge adaptive scheme which can select the embedding regions according to the size of secret message and the difference between two consecutive pixels in the cover image.For lower embedding rates, only sharper edge regions are used while keeping the other smoother regions as they are. LSB replacement is a well-known steganographic method. In this embedding scheme, only the LSB plane of the cover image is overwritten with the secret bit stream according to a pseudorandom number generator (PRNG). \par LSB matching (LSBM) employs a minor modification to LSB replacement. If the secret bit does not match the LSB of the cover image, then $\pm 1$ is randomly added to the corresponding pixel value. The experimental results demonstrated that the method was more effective on uncompressed grayscale im ages. \par LSB matching revisited (LSBMR) uses a pair of pixels as an embedding unit, in which the LSB of the first pixel carries one bit of secret message, and the relationship (odd–even combination) of the two pixel values carries another bit of secret message. In such a way, the modification rate of pixels can decrease from 0.5 to 0.375 bits/pixel (bpp) in the case of a maximum embedding rate, meaning fewer changes to the cover image at the same payload compared to LSB replacement and LSBM. The typical LSB-based approaches, including LSB replacement, LSBM, and LSBMR, deal with each given pixel/pixelpair without considering the difference between the pixel and its neighbors. \par The pixel-value differencing (PVD)-based scheme is another kind of edge adaptive scheme, in which the number of embedded bits is determined by the difference between a pixel and its neighbor. The larger the difference, the larger the number of secret bits that can be embedded. Usually, PVD-based approaches can provide a larger embedding capacity. Generally, the regions located at the sharper edges present more complicated statistical features and are highly dependent on the image contents. Moreover, it is more difficult to observe changes at the sharper edges than those in smooth regions. \par For LSB replacement, the secret bit simply overwrites the LSB of the pixel, i.e., the first bit plane, while the higher bit planes are preserved. For the LSBM scheme, if the secret bit is not equal to the LSB of the given pixel, then 1 is added randomly to the pixel while keeping the altered pixel in the range of $[0, 255]$. \par Our human vision is sensitive to slight changes in the smooth regions, while it can tolerate more severe changes in the edge regions.The basic idea of PVD-based approaches is to first divide the cover image into many nonoverlapping units with two consecutive pixels and then deal with the embedding unit along a pseudorandom order which is also determined by a PRNG. The larger the difference between the two pixels, the larger the number of secret bits that can be embedded into the unit. \par We find that uncompressed natural images usually contain some flat regions (it may be as small as 5X5 and it is hard to notice), If we embed data into these regions, the LSB of stego images would become more and more random. Our proposed scheme will first embed the secret bits into edge regions as far as possible while keeping other smooth regions as they are. We have not much focused on the security and safety of our data and image. In this paper, we apply such a region adaptive scheme to the spatial LSB domain. We use the absolute difference between two adjacent pixels as the criterion for region selection, and use LSBMR as the data hiding algorithm. We have taken two parameters for data hiding approach. The first one is the block size for block dividing in data preprocessing; another is the threshold for embedding region selection. The larger the number of secret bits to be embedded, the smaller the threshold $T$ becomes, which means that more embedding units with lower gradients in the cover image can be released. When $T$ is 0, all the embedding units within the cover become available. In such a case, our method can achieve the maximum embedding capacity of 100 \%. \par Our technique of implementation takes LSB of pixels in a ordered manner i.e. divide the image into blocks, convert them into a row of block vector (just for the ease of computation), rotate each block by a certain random angle, store data using LSBMR technique and bring it back to as the blocks were placed in the previous image. Rotating images and then storing data could make the data scrambled and somebody who tries to debug could not be able to get the data in a particular manner. What more could we do was when the blocks were made, we could’ve traversed the last two or three blocks from all the edge (depending on the bits of the message) to a certain place keeping a record of it and then rotating them and storing the data. Then moving them back to their original place. This could make debugging even more difficult. \newpage \section{Conclusions and Results} We conclude the report by saying that what we aimed at while implemenenting the paper has been achieved. We ought to target image steganography and for that we tried using edge adaptive techniques. Although, the author of the code did not implemented the paper in its full essence but the code is working as expected by the author. Few points that must be noted about what implementations have been achieved and what has been not before we conclude with the results. Note: The code has been authored by Himanshu Sharma (Member - 1). \\ \underline{\large What has been achieved in the Python code base} \begin{enumerate} \item Graphical User Interface has been developed so that anyone can use this software piece. \item Division of image into blocks of dimension $B \times B$ and then their random rotations has been implemented so as to increase the security as given in the paper. \item Bit Planes were implemented as they were given in the paper. A special Python script is dedicated for this only. \item LSB Matching algorithm as given in the paper has been implemented successfully. \item Image steganography has been done successfully. \end{enumerate} \par \underline{\large What the author was unable to implement in the code} \begin{enumerate} \item Because the ``argmin" and ``argmax" operations seemed difficult and therefore steps 2 and 3 of the algorithm (refer the paper) suggested in the paper were not implemented precisely. Instead, a linear form of steganography was done as a substitute to these steps. \end{enumerate} If we have to summarize, we summarize the results by operating on the popular test image used in the field of image processing, i.e., the popular photograph of model Lenna S\"{o}derberg. \begin{figure}[H] \centering \begin{minipage}{0.46\linewidth} \centering \includegraphics[width=0.7\textwidth]{images/lenna.png} \caption{Cover Image} \end{minipage} \hfill \begin{minipage}{0.46\linewidth} \centering \includegraphics[width=0.7\textwidth]{images/stego-lenna.png} \caption{Stego Image} \end{minipage} \end{figure} Clearly, there is no difference in the cover and the stego image. Just to convey the information, I am also showing the MSB and LSB planes of the cover and the stego-image. Note how easy would it have been for an attacker if we would store our data inside the MSB plane (see the figures below). The following text is hidden in the stego image. \begin{center} \begin{ppl} Steganography includes the concealment of information within computer files. In digital steganography, electronic communications may include steganographic coding inside of a transport layer, such as a document file, image file, program or protocol. Media files are ideal for steganographic transmission because of their large size. For example, a sender might start with an innocuous image file and adjust the color of every hundredth pixel to correspond to a letter in the alphabet. The change is so subtle that someone who is not specifically looking for it is unlikely to notice the change. \end{ppl} \end{center} \begin{figure}[H] \centering \begin{minipage}{0.46\linewidth} \centering \includegraphics[width=0.7\textwidth]{images/covermsb.png} \caption{MSB plane of the Cover} \end{minipage} \hfill \begin{minipage}{0.46\linewidth} \centering \includegraphics[width=0.7\textwidth]{images/coverlsb.png} \caption{LSB plane of the Cover} \end{minipage} \end{figure} \begin{figure}[H] \centering \begin{minipage}{0.46\linewidth} \centering \includegraphics[width=0.7\textwidth]{images/stegomsb.png} \caption{MSB plane of the Stego} \end{minipage} \hfill \begin{minipage}{0.46\linewidth} \centering \includegraphics[width=0.7\textwidth]{images/stegolsb.png} \caption{LSB plane of the Stego} \end{minipage} \end{figure} We conclude by saying that image steganography has been implemented successfully and we got the results as expected. \\ \par \begin{center} \textbf{IMPORTANT NOTE} \end{center} \par Full code base is available at Member 1's Github repository - {\bf https://github.com/hmnhGeek/DSP-Project-Report-LaTeX}. We request the reader to please visit and see the code base for atleast once. \begin{center} \decosix\decosix\decosix \end{center} \end{document}
\section{Seasoning}
\documentclass[12pt]{article} \usepackage{graphicx} \usepackage[utf8]{inputenc} \usepackage[nottoc]{tocbibind} \usepackage{graphicx} \usepackage{wrapfig} \usepackage{url} \begin{document} %===================================TTLE PAGE===================================% \title{Differential Equations for the Growth of Coral Polyps of the Genus \textit{Acropora}} \author{Kyle Spooner, Ethan Puerto, and Holly Pafford} \maketitle \newpage %===================================CONTENTS====================================% \tableofcontents \newpage %===================================ABSTRACT====================================% \section{Abstract} Coral farming and propagation is necessary due the decline in coral reef habitats around the world. One the Caribbean's most ``predominant reef-building coral'' genera, \textit{Acropora}, is also facing the same problem. This has resulted in a decrease of reef function which in turn causes widespread oceanic population decline. In the propagation of \textit{Acropora}, the polyp population can be estimated by a simple exponential growth differential equation model. We will analyze the exponential growth of these polyps using the relationship of the number of starting polyps and time, with this information we can estimate coral regeneration rates. \newpage \section{Introduction} Oceans cover approximately 71 percent of the Earth’s surface. Within these bodies of water, coral reefs exist. Reefs are key to developing new types of medications for curing infections, diseases, and even cancer. In addition to that, reefs have been a major food source for millions across the globe for eons. The reef ecosystem is vital to the ocean as a whole, it is part of every food chain and is the backbone for all life in the ocean. Reefs are the product of millions of years of growth and development, the reefs we see and rely on today are built on Acropora from the past.\cite{wiki:Acropora} \begin{wrapfigure}{r}{0.6\textwidth} \begin{center} \includegraphics[width=0.48\textwidth]{acroplate} \end{center} \caption{Branching Plate \textit{Acropora}\cite{wiki:Acropora}} \end{wrapfigure} \textit{Acropora} is defined as a ``small polyp stony coral''. This genus, in particular, is responsible for building the calcium carbonate substructure that helps to support the frame of a reef ecosystem. Approximately 149 species of \textit{Acropora} has been identified. These species can come in a variety of forms, such as plates and branches. All \textit{Acropora} corals are essentially colonies of many individual polyps that have the ability to withdraw back into their hard exoskeleton as a response to sudden movement in the area which may be a potential predator. Recently, there has been a population decline caused by environmental destruction; therefore, propagation of \textit{Acropora} is necessary to keep reef ecosystems alive.\cite{wiki:Acropora} \subsection{\textit{Acropora} Growth Through Propagation} Propagation is when a small fragment of coral is taken from a much larger colony. This fragment, or frag, then reproduces asexually resulting a large colony of its own. Multiple methods exist for propagating coral. These methods are divided into one of two types, “floating” propagation or “fixed to the bottom” propagation. In floating propagation,the coral frag is tethered to a line above the ocean floor. In this case, coral is capable of growing in any direction due to being suspended in the water column. In fixed to the bottom propagation, frags are attached to ceramic plugs, cinder blocks, or various other materials and placed on what is essentially a table. In this placement the coral growth is limited to upwards and outwards growth. By using these methods we can help stimulate the growth of coral colonies and aid in the restoration of coral reefs.\cite{GrowthDynamics} \begin{figure}[h] \centering \includegraphics[width=0.6\textwidth]{acroprop} \caption{Propogation methods for \textit{Acropora}\cite{GrowthDynamics}} \end{figure} %==================================CONTENT======================================% \section{The Equation for Modeling Polyp Growth} In order to properly model the growth of these polyps we must first take into account the various aspects of this problem. With the growth of \textit{Acropora}, or any animal for that matter, we must understand its growth rate and factor that into our solution. In addition to that, time, and starting population are necessary to allow for a broad a general solution and model. The differential equation that results is the same used to model most exponentially growing population\cite{BaseFunction}, \begin{equation} \frac{dy}{dt} = ky \end{equation} Rearanging the equation allows it to be integrated on each side with respects to $y$ and $t$ \begin{equation} \frac{1}{y}\frac{dy}{dt}=k \end{equation} From this point we must manipulate the equations to allow for a clean integration of boths sides in terms of $dy$ on the left and $dt$ on the left. \begin{equation} \frac{1}{y}dy=kdt \end{equation} Now we can integrate both sides with there own respects. \begin{equation} \int{\frac{1}{y}}dy = \int {k}dt \end{equation} Since we know the integral of $\frac{1}{y}$ with respects to $y$ and the integral of a constant $k$, we can derive the following solution. \begin{equation} ln(y)= kt+c \end{equation} For the final step in deriving the solution we must isolate $y$. Using log rules we can remove $ln()$ from $ln(y)$. \begin{equation} y=Ce^{kt} \end{equation} At this point, the equation can be used to model any species of coral. Sample data, including a starting number of polyps, end number of polyps, and time between would be used to determine the rate constant k. This equation also resembles the Malthusian Growth Model. \subsection{Malthusian Growth Model} This model is used to represent the growth of various populations over a generally short period of time. This is due to the simple exponential properties of this equation which results in an infinite solution, when in reality it is never as such.\cite{wiki:Equation} The equation is as follows, \begin{equation} P(t)= P_{0}e^{rt} \end{equation} Where, \begin{itemize} \item $P_{0}$ is the initial population size \item $r$ is the growth rate \item $t$ is the length of time \end{itemize} \section{Modeling Growth using the Solution} \subsection{Solving for $P(t)$} A Staghorn Coral (\textit{Acropora cervicornis}) of length $10cm$ can grow up to $200mm$ in its first year. With an average number of polyps per linear millimeter of \textit{Acropora} being $10$, we can find the rate constant for this species.\cite{AcroStats} First we must find the starting polyps for $10cm$ of coral, \begin{equation} 100mm*10=1000 \end{equation} Using this, we can also find the final population after a year knowing that \textit{Acropora Staghorn} grows at a race of 200mm per year. \begin{equation} P(t)=1000+2000=3000 \end{equation} \subsection{Finding the Growth Rate Constant $k$} Now by substituting in the values of $P(t)$,$P_{0}$, and $t=1$; we can solve for our growth rate $k$ \begin{equation} 3000 = 1000e^{k(1)} \end{equation} \begin{equation} 3=1e^{k} \end{equation} \begin{equation} ln3=k \end{equation} \begin{equation} k=1.0986 \end{equation} \subsection{Growth Estimation} We can now use this information to estimate the length of staghorn coral for various periods of time. For example, a coral containing 500 polyps that grows under ideal conditions for 5 years would reach a population of: \begin{equation} P = 500e^{1.0986(5)} = 12,150 \end{equation} This resultant coral of 12,150 polyps, would have a length of \begin{equation} \frac{12150 Polyps}{10 Polyps Per Millimeter} =1125mm=1.25m \end{equation} \textit{(This length is the overall tip to tail length of all branches added together, not of each branch.) } The average length of a branch of staghorn is $10cm$\cite{AcroStats}. With this we can also solve for the final number of branches. \begin{equation} \frac{1.25m}{10cm}=11.25 \end{equation} Finding the changes in number of polyps in a coral allows us to gather a variety of information on the coral, including estimations in length, growth rate and branch production. This same process can be applied to any species of the genus acropora, as long as experimental data can be supplied to determine the rate constant. \newpage \subsection{Matlab Estimation} The estimation of equation 14 in matlab is as follows, \begin{center} \includegraphics[width=1\textwidth]{PolypPopGrowth} \end{center} \newpage \section{Conclusion} Exponential growth is a great way for estimating the time at which a particular species needs to re-populate itself. For example, \textit{Acropora} is not re-populating itself fast enough for the survival of reef habitats; therefore, propagation of \textit{Acropora} must take place. The chosen differential equation and derived solution is necessary for the estimated growth rate of A\textit{Acropora} (i.e. Staghorn). The equation may be used for estimating the growth rate of any coral genus; however, the constant(s) must be altered according to the specific species. The solution allows the researcher to alter the coral’s environment to reach full production. \newpage \bibliographystyle{plain} - \bibliography{bib} \end{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % INTRODUCTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \section{Introduction} The aim of this report is to detail the work undertaken into implementing the calculation of statistical values from large datasets derived from natural processes. `Statistical values' was understood as descriptive statistics that summarise a data set through representative scalar values, such as minimum, mean, standard deviation. We took `natural processes' to mean a process that generates a data stream of continuous values with existing statistical values. Finally, the term `large data sets' was taken to mean anything that is inefficient to process through ordinary means, but still manageable on a shared-memory system as distributed systems are out of our scope (on the order of $10^9$, <10GiB).
\documentclass[../main.tex]{subfiles} \begin{document} In this chapter, we will specifically talk math related problems. Normally, for the problems appearing in this section, they can be solved using our learned programming methodology. However, it might not inefficient (we will get LTE error on the LeetCode) due to the fact that we are ignoring their math properties which might help us boost the efficiency. Thus, learning some of the most related math knowledge can make our life easier. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % sorting %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % GCD %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \section{Numbers} \subsection{Prime Numbers} A prime number is an integer greater than 1, which is only divisible by 1 and itself. First few prime numbers are : 2 3 5 7 11 13 17 19 23 ... Some interesting facts about Prime numbers: \begin{enumerate} \item 2 is the only even Prime number. \item 2, 3 are only two consecutive natural numbers which are prime too. \item \label{divide}Every prime number except 2 and 3 can represented in form of 6n+1 or 6n-1, where n is natural number. \item \label{godld} Goldbach Conjecture: Every even integer greater than 2 can be expressed as the sum of two primes. Every positive integer can be decomposed into a product of primes. \item GCD of a natural number with Prime is always one. \item Fermat’s Little Theorem: If n is a prime number, then for every a, $1 <= a < n $, %$a^{(n-1)} == 1 (mod n) OR a^(n-1) % n = 1$. check if it is useful in real situation \item Prime Number Theorem : The probability that a given, randomly chosen number n is prime is inversely proportional to its number of digits, or to the logarithm of n. \end{enumerate} \subsubsection{Check Single Prime Number} Learning to check if a number is a prime number is necessary: the naive solution comes from the direct definition, for a number $n$, we try to check if it can be divided by number in range $[2, n-1]$, if it divides, then its not a prime number. \begin{lstlisting}[language=Python] def isPrime(n): # Corner case if (n <= 1): return False # Check from 2 to n-1 for i in range(2, n): if (n % i == 0): return False return True \end{lstlisting} There are actually a lot of space for us to optimize the algorithm. First, instead of checking till n, we can check till $\sqrt{n}$ because a larger factor of n must be a multiple of smaller factor that has been already checked. Also, because even numbers bigger than 2 are not prime, so the step we can set it to 2. The algorithm can be improved further by use feature \ref{divide} that all primes are of the form $6k \pm 1$, with the exception of 2 and 3. Together with feature \ref{godld} which implicitly states that every non-prime integer is divisible by a prime number smaller than itself. So a more efficient method is to test if n is divisible by 2 or 3, then to check through all the numbers of form $6k \pm 1$. \begin{lstlisting}[language=Python] def isPrime(n): # corner cases if n <= 1: return False if n<= 3: return True if n % 2 == 0 or n % 3 == 0: return False for i in range(5, int(n**0.5)+1, 6): # 6k+1 or 6k-1, step 6, up till sqrt(n), when i=5, check 5 and 7, (k-1, k+1) if n%i == 0 or n%(i+2)==0: return False return True return True \end{lstlisting} \subsubsection{Generate A Range of Prime Numbers} \paragraph{Wilson theorem} says if a number k is prime then $((k-1)! + 1) \% k$ must be 0. Below is Python implementation of the approach. Note that the solution works in Python because Python supports large integers by default therefore factorial of large numbers can be computed. \begin{lstlisting}[language=Python] # Wilson Theorem def primesInRange(n): fact = 1 rst = [] for k in range(2, n): fact *= (k-1) if (fact + 1)% k == 0: rst.append(k) return rst print(primesInRange(15)) # output # [2, 3, 5, 7, 11, 13] \end{lstlisting} \paragraph{Sieve Of Eratosthenes} To generate a list of primes. It works by recognizing \textit{Goldbach Conjecture} that all non-prime numbers are divisible by a prime number. An optimization is to only use odd number in the primes list, so that we can save half space and half time. The only difference is we need to do index mapping. \begin{lstlisting}[language=Python] def primesInRange(n): primes = [True] * n primes[0] = primes[1] = False for i in range(2, int(n ** 0.5) + 1): #cross off remaining multiples of prime i, start with i*i if primes[i]: for j in range(i*i,n,i): primes[j] = False rst = [] # or use sum(primes) to get the total number for i, p in enumerate(primes): if p: rst.append(i) return rst print(primesInRange(15)) \end{lstlisting} \subsection{Ugly Numbers} Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. We can write it as $ugly number = 2^i3^j5^k, i>=0, j>=0, k>=0$. Examples of ugly numbers: 1, 2, 3, 5, 6, 10, 15, ... The concept of ugly number is quite simple. Now let us use the LeetCode problems as example to derive the algorithms to identify ugly numbers. \subsubsection{Check a Single Number} 263. Ugly Number (Easy) \begin{lstlisting} Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly since it includes another prime factor 7. Note: 1 is typically treated as an ugly number. Input is within the 32-bit signed integer range. \end{lstlisting} Analysis: because the ugly number is only divisible by $2, 3, 5$, so if we keep dividing the number by these factors ($num/f$), eventually we would get $1$, if the reminder ($num\%f$) is $0$ (divisible), otherwise we stop the loop to check the number. \begin{lstlisting}[language = Python] def isUgly(self, num): """ :type num: int :rtype: bool """ if num ==0: return False factor = [2,3,5] for f in factor: while num%f==0: num/=f return num == 1 \end{lstlisting} \subsubsection{Generate A Range of Number} 264. Ugly Number II (medium) \begin{lstlisting} Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 is the sequence of the first 10 ugly numbers. Note that 1 is typically treated as an ugly number, and n does not exceed 1690. \end{lstlisting} Analysis: The first solution is we use the rules $ugly number = 2^i3^j5^k, i>=0, j>=0, k>=0$, using three for loops to generate at least 1690 ugly numbers that is in the range of $2^32$, and then sort them, the time complexity is $O(nlogn)$, with $O(n)$ in space. However, if we need to constantly make request, it seems resasonable to save a table, and once the table is generated and saved, each time we would only need constant time to check. \begin{lstlisting}[language = Python] from math import log, ceil class Solution: ugly = [2**i * 3**j * 5**k for i in range(32) for j in range(ceil(log(2**32, 3))) for k in range(ceil(log(2**32, 5)))] ugly.sort() def nthUglyNumber(self, n): """ :type n: int :rtype: int """ return self.ugly[n-1] \end{lstlisting} The second way is only generate the nth ugly number, with \begin{lstlisting}[language=Python] class Solution: n = 1690 ugly = [1] i2 = i3 = i5 = 0 for i in range(n-1): u2, u3, u5 = 2 * ugly[i2], 3 * ugly[i3], 5 * ugly[i5] umin = min(u2,u3,u5) ugly.append(umin) if umin == u2: i2 += 1 if umin == u3: i3 += 1 if umin == u5: i5 += 1 def nthUglyNumber(self, n): """ :type n: int :rtype: int """ return self.ugly[n-1] \end{lstlisting} %%%%%%%%%Combinatorics%%%% \subsection{Combinatorics} \begin{enumerate} \item 611. Valid Triangle Number \end{enumerate} \begin{examples}[resume] \item \textbf{Pascal's Triangle II(L119, *).} Given a non-negative index k where k <= 33, return the kth index row of the Pascal's triangle. Note that the row index starts from 0. In Pascal's triangle, each number is the sum of the two numbers directly above it. \begin{lstlisting}[numbers=none] Example: Input: 3 Output: [1,3,3,1] \end{lstlisting} Follow up: Could you optimize your algorithm to use only O(k) extra space? \textbf{Solution: Generate from Index 0 to K}. \begin{lstlisting}[language=Python] def getRow(self, rowIndex): if rowIndex == 0: return [1] # first, n = rowIndex+1, if n is even, ans = [1] for i in range(rowIndex): tmp = [1]*(i+2) for j in range(1, i+1): tmp[j] = ans[j-1]+ans[j] ans = tmp return ans \end{lstlisting} Triangle Counting \end{examples} %%%%%%%%%%%Others%%%%%%%%%%% \subsubsection{Smallest Larger Number} 556. Next Greater Element III \begin{lstlisting} Given a positive 32-bit integer n, you need to find the smallest 32-bit integer which has exactly the same digits existing in the integer n and is greater in value than n. If no such positive 32-bit integer exists, you need to return -1. Example 1: Input: 12 Output: 21 Example 2: Input: 21 Output: -1 \end{lstlisting} Analysis: The first solution is to get all digits [1,2], and generate all the permutation [[1,2],[2,1]], and generate the integer again, and then sort generated integers, so that we can pick the next one that is larger. But the time complexity is O(n!). Now, let us think about more examples to find the rule here: \begin{lstlisting} 435798->435879 1432->2134 \end{lstlisting} If we start from the last digit, we look to its left, find the cloest digit that has smaller value, we then switch this digit, if we cant find such digit, then we search the second last digit. If none is found, then we can not find one. Like 21. return -1. This process is we get the first larger number to the right. \begin{lstlisting} [5, 5, 7, 8, -1, -1] [2, -1, -1, -1] \end{lstlisting} After the this we switch 8 with 7: we get \begin{lstlisting} 4358 97 2 431 \end{lstlisting} For the reminding digits, we do a sorting and put them back to those digit to get the smallest value \begin{lstlisting}[language=Python] class Solution: def getDigits(self, n): digits = [] while n: digits.append(n%10) # the least important position n = int(n/10) return digits def getSmallestLargerElement(self, nums): if not nums: return [] rst = [-1]*len(nums) for i, v in enumerate(nums): smallestLargerNum = sys.maxsize index = -1 for j in range(i+1, len(nums)): if nums[j]>v and smallestLargerNum > nums[j]: index = j smallestLargerNum = nums[j] if smallestLargerNum < sys.maxsize: rst[i] = index return rst def nextGreaterElement(self, n): """ :type n: int :rtype: int """ if n==0: return -1 digits = self.getDigits(n) digits = digits[::-1] # print(digits) rst = self.getSmallestLargerElement(digits) # print(rst) stop_index = -1 # switch for i in range(len(rst)-1, -1, -1): if rst[i]!=-1: #switch print('switch') stop_index = i digits[i], digits[rst[i]] = digits[rst[i]], digits[i] break if stop_index == -1: return -1 # print(digits) # sort from stop_index+1 to the end digits[stop_index+1:] = sorted(digits[stop_index+1:]) print(digits) #convert the digitialized answer to integer nums = 0 digit = 1 for i in digits[::-1]: nums+=digit*i digit*=10 if nums>2147483647: return -1 return nums \end{lstlisting} \section{Intersection of Numbers} In this section, intersection of numbers is to find the ``common" thing between them, for example Greatest Common Divisor and Lowest Common Multiple. \subsection{Greatest Common Divisor} GCD (Greatest Common Divisor) or HCF (Highest Common Factor) of two numbers $a$ and $b$ is the largest number that divides both of them. For example shown as follows: \begin{lstlisting} The divisors of 36 are: 1, 2, 3, 4, 6, 9, 12, 18, 36 The divisors of 60 are: 1, 2, 3, 4, 5, 6, 10, 12, 15, 30, 60 GCD = 12 \end{lstlisting} Special case is when one number is zero, the GCD is the value of the other. $gcd(a, 0) = a$. The basic algorithm is: we get all divisors of each number, and then find the largest common value. Now, let's see how to we advance this algorithm. We can reformulate the last example as: \begin{lstlisting} 36 = 2 * 2 * 3 * 3 60 = 2 * 2 * 3 * 5 GCD = 2 * 2 * 3 = 12 \end{lstlisting} So if we use $60-36 = 2*2*3*5 - 2*2*3*3 = (2*2*3)*(5-3) = 2*2*3*2$. So we can derive the principle that the GCD of two numbers does not change if the larger number is replaced by its difference with the smaller number. The features of GCD: \begin{enumerate} \item $gcd(a, 0) = a$ \item $gcd(a, a) = a$, \item $gcd(a, b) = gcd(a-b, b)$, if $a>b$. \end{enumerate} Based on the above features, we can use Euclidean Algorithm to gain GCD: \begin{lstlisting} def euclid(a, b): while a != b: # replace larger number by its difference with the smaller number if a > b: a = a - b else: b = b - a return a print(euclid(36, 60)) \end{lstlisting} The only problem with the Euclidean Algorithm is that it can take several subtraction steps to find the GCD if one of the given numbers is much bigger than the other. A more efficient algorithm is to replace the subtraction with remainder operation. The algorithm would stops when reaching a zero reminder and now the algorithm never requires more steps than five times the number of digits (base 10) of the smaller integer. The recursive version code: \begin{lstlisting}[language = Python] def euclidRemainder(a, b): if a == 0 : return b return gcd(b%a, a) \end{lstlisting} The iterative version code: \begin{lstlisting}[language = Python] def euclidRemainder(a, b): while a > 0: # replace one number with reminder between them a, b = b%a, a return b print(euclidRemainder(36, 60)) \end{lstlisting} \subsection{Lowest Common Multiple} Lowest Common Multiple (LCM) is the smallest number that is a multiple of both $a$ and $b$. For example of 6 and 8: \begin{lstlisting} The multiplies of 6 are: 6, 12, 18, 24, 30, ... The multiplies of 8 are: 8, 16, 24, 32, 40, ... LCM = 24 \end{lstlisting} Computing LCM is dependent on the GCD with the following formula: \begin{equation} lcm(a, b) = \frac{a\times b}{gcd(a, b)} \end{equation} \section{Arithmetic Operations} Because for the computer, it only understands the binary representation as we learned in Bit Manipulation (Chapter~\ref{chapter_bit}, the most basic arithmetic operation it supports are binary addition and subtraction. (Of course, it can execute the bit manipulation too.) The other common arithmetic operations such as Multiplication, division, modulus, exponent are all implemented/coded with the addition and subtraction as basis or in a dominant fashion. As a software engineer, have a sense of how we can implement the other operations from the given basis is reasonable and a good practice of the coding skills. Also, sometimes if the factor to compute on is extra large number, which is to say the computer can not represent, we can still compute the result by treating these numbers as strings. In this section, we will explore operations include multiplication, division. There are different algorithms that we can use, we learn a standard one called long multiplication and long division. I am assuming you know the algorithms and focusing on the implementation of the code instead. \paragraph{Long Multiplication} \paragraph{Long Division} We treat the dividend as a string, e.g. dividend = 3456, and the divisor = 12. We start with 34, which has the digits as of divisor. 34/12 = 2, 10, where 2 is the integer part and 10 is the reminder. Next step, we take the reminder and join with the next digit in the dividend, we get 105/12 = 8, 9. Smilarily, 96/12 = 8, 0. Therefore we get the results by joinging the result of each dividending operation, '288'. To see the coding, let us code it the way required by the following LeetCode Problem. In the process we need (n-m) (n, m is the total number of digits of dividend and divisor, respectively) division operation. Each division operation will be done at most 9 steps. This makes the time complexity $O(n-m)$. \begin{examples}[resume] \item \textbf{29. Divide Two Integers (medium)} Given two integers dividend and divisor, divide two integers without using multiplication, division and mod operator. Return the quotient after dividing dividend by divisor. The integer division should truncate toward zero. \begin{lstlisting}[language=Python][numbers=none] Example 1: Input: dividend = 10, divisor = 3 Output: 3 Example 2: Input: dividend = 7, divisor = -3 Output: -2 \end{lstlisting} \textbf{Analysis:} we can get the sign of the result first, and then convert the dividend and divisor into its absolute value. Also, we better handle the bound condition that the divisor is larger than the vidivend, we get 0 directly. The code is given: \begin{lstlisting}[language=Python] def divide(self, dividend, divisor): def divide(dd): # the last position that divisor* val < dd s, r = 0, 0 for i in range(9): tmp = s + divisor if tmp <= dd: s = tmp else: return str(i), str(dd-s) return str(9), str(dd-s) if dividend == 0: return 0 sign = -1 if (dividend >0 and divisor >0 ) or (dividend < 0 and divisor < 0): sign = 1 dividend = abs(dividend) divisor = abs(divisor) if divisor > dividend: return 0 ans, did, dr = [], str(dividend), str(divisor) n = len(dr) pre = did[:n-1] for i in range(n-1, len(did)): dd = pre+did[i] dd = int(dd) v, pre = divide(dd) ans.append(v) ans = int(''.join(ans))*sign if ans > (1<<31)-1: ans = (1<<31)-1 return ans \end{lstlisting} \end{examples} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Probability Theory %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \section{Probability Theory} In programming tasks, such problems are either solvable with some closed-form formula or one has no choice than to enumerate the complete search space. \section{Linear Algebra} \textit{Gaussian Elimination} is one of the several ways to find the solution for a system of linear euqations. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % geometry %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \section{Geometry} In this section, we will discuss coordinate related problems. 939. Minimum Area Rectangle(Medium) Given a set of points in the xy-plane, determine the minimum area of a rectangle formed from these points, with sides parallel to the x and y axes. If there isn't any rectangle, return 0. \begin{lstlisting} Example 1: Input: [[1,1],[1,3],[3,1],[3,3],[2,2]] Output: 4 Example 2: Input: [[1,1],[1,3],[3,1],[3,3],[4,1],[4,3]] Output: 2 \end{lstlisting} \textbf{Combination}. This at first it is a combination problem, we pick four points and check if it is a rectangle and then what is the size. However the time complexity can be $C_n^k$, which will be $O(n^4)$. The following code implements the best combination we get, however, we receive LTE: \begin{lstlisting}[language=Python] def minAreaRect(self, points): def combine(points, idx, curr, ans): # h and w at first is -1 if len(curr) >= 2: lx, rx = min([x for x, _ in curr]), max([x for x, _ in curr]) ly, hy = min([y for _, y in curr]), max([y for _, y in curr]) size = (rx-lx)*(hy-ly) if size >= ans[0]: return xs = [lx, rx] ys = [ly, hy] for x, y in curr: if x not in xs or y not in ys: return if len(curr) == 4: ans[0] = min(ans[0], size) return for i in range(idx, len(points)): if len(curr) <= 3: combine(points, i+1, curr+[points[i]], ans) return ans=[sys.maxsize] combine(points, 0, [], ans) return ans[0] if ans[0] != sys.maxsize else 0 \end{lstlisting} \textbf{Math: Diagonal decides a rectangle}. We use the fact that if we know the two diagonal points, say (1, 2), (3, 4). Then we need (1, 4), (3, 2) to make it a rectangle. If we save the points in a hashmap, then the time complexity can be decreased to $O(n^2)$. The condition that two points are diagonal is: x1 != x2, y1 != y2. If one of them is equal, then they form a vertical or horizontal line. If both equal, then its the same points. \begin{lstlisting}[language = Python] class Solution(object): def minAreaRect(self, points): S = set(map(tuple, points)) ans = float('inf') for j, p2 in enumerate(points): # decide the second point for i in range(j): # decide the firs point p1 = points[i] if (p1[0] != p2[0] and p1[1] != p2[1] and # avoid (p1[0], p2[1]) in S and (p2[0], p1[1]) in S): ans = min(ans, abs(p2[0] - p1[0]) * abs(p2[1] - p1[1])) return ans if ans < float('inf') else 0 \end{lstlisting} \textbf{Math: Sort by column}. Group the points by x coordinates, so that we have columns of points. Then, for every pair of points in a column (with coordinates (x,y1) and (x,y2)), check for the smallest rectangle with this pair of points as the rightmost edge. We can do this by keeping memory of what pairs of points we've seen before. \begin{lstlisting}[language=Python] def minAreaRect(self, points): columns = collections.defaultdict(list) for x, y in points: columns[x].append(y) lastx = {} # one-pass hash ans = float('inf') for x in sorted(columns): # sort by the keys column = columns[x] column.sort() # sort column for j, y2 in enumerate(column): # right most edge, up point for i in xrange(j): # right most edge, lower point y1 = column[i] if (y1, y2) in lastx: # 1: [1, 3], will be saved, when we were at 3: [1, 3], we can get the answer ans = min(ans, (x - lastx[y1,y2]) * (y2 - y1)) lastx[y1, y2] = x # y1, y2 form a tuple return ans if ans < float('inf') else 0 \end{lstlisting} \section{Miscellaneous Categories} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%% rabbit and turtle to find circle or repeat number %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \subsection{Floyd’s Cycle-Finding Algorithm} Without this we detect cycle with the following code: \begin{lstlisting}[language = Python] def detectCycle(self, A): visited=set() head=point=A while point: if point.val in visited: return point visited.add(point) point=point.next return None \end{lstlisting} Traverse linked list using two pointers. Move one pointer by one and other pointer by two. If these pointers meet at some node then there is a loop. If pointers do not meet then linked list doesn’t have loop. Once you detect a cycle, think about finding the starting point. \begin{figure}[h!] \centering \includegraphics[width = 0.98\columnwidth]{fig/floyd.png} \caption{Example of floyd’s cycle finding} \label{fig:floyd} \end{figure} \begin{lstlisting}[language = Python] def detectCycle(self, A): #find the "intersection" p_f=p_s=A while (p_f and p_s and p_f.next): p_f = p_f.next.next p_s = p_s.next if p_f==p_s: break #Find the "entrance" to the cycle. ptr1 = A ptr2 = p_s; while ptr1 and ptr2: if ptr1!=ptr2: ptr1 = ptr1.next ptr2 = ptr2.next else: return ptr1 return None \end{lstlisting} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % exercise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \section{Exercise} \subsection{Number} 313. Super Ugly Number \begin{lstlisting} Super ugly numbers are positive numbers whose all prime factors are in the given prime list primes of size k. For example, [1, 2, 4, 7, 8, 13, 14, 16, 19, 26, 28, 32] is the sequence of the first 12 super ugly numbers given primes = [2, 7, 13, 19] of size 4. Note: (1) 1 is a super ugly number for any given primes. (2) The given numbers in primes are in ascending order. (3) 0 < k <= 100, 0 < n <= 106, 0 < primes[i] < 1000. (4) The nth super ugly number is guaranteed to fit in a 32-bit signed integer. \end{lstlisting} \begin{lstlisting}[language=Python] def nthSuperUglyNumber(self, n, primes): """ :type n: int :type primes: List[int] :rtype: int """ nums=[1] idexs=[0]*len(primes) #first is the current idex for i in range(n-1): min_v = maxsize min_j = [] for j, idex in enumerate(idexs): v = nums[idex]*primes[j] if v<min_v: min_v = v min_j=[j] elif v==min_v: min_j.append(j) #we can get mutiple j if there is a tie nums.append(min_v) for j in min_j: idexs[j]+=1 return nums[-1] \end{lstlisting} \end{document}
\section{Task Description} Review of the existent space rovers. With conclusions on the end (5-10 pages, no more)
%\documentclass[English, 11pt, twoside, authoryear]{article} %%\setlength{\columnsep}{20pt} % column separation width %%\usepackage{txfonts} %font package that is more up to dater than times %\usepackage{natbib} %%\usepackage{graphicx} %%\usepackage{wrapfig} %\usepackage{subfigure} %% make it possible to include more than one captioned figure/table in a single float %%\usepackage{color} %%\usepackage{multicol} %\usepackage{multirow} %\usepackage{colortbl} %%\usepackage{booktabs} %%\usepackage{topcapt} % top caption for tables %%\usepackage{a4wide} % makes the text on a page wider %%\usepackage{booktabs} % for much better looking tables %%\usepackage{paralist} % very flexible & customisable lists (eg. enumerate/itemize, etc.) %%\usepackage{verbatim} % adds environment for commenting out blocks of text & for better verbatim %% %\usepackage{pdflscape} % %\usepackage{ctable} % %\newcommand{\marginal}[1]{ % \leavevmode\marginpar{\tiny\raggedright#1\par}} % %%% LaTeX Preamble - Common packages % %%\usepackage[utf8]{inputenc} % Any characters can be typed directly from the keyboard, eg éçñ %%\usepackage{textcomp} % provide lots of new symbols %%\usepackage{graphicx} % Add graphics capabilities %%\usepackage{epstopdf} % to include .eps graphics files with pdfLaTeX %%\usepackage{flafter} % Don't place floats before their definition %%\usepackage{topcapt} % Define \topcation for placing captions above tables (not in gwTeX) %%\usepackage{natbib} % use author/date bibliographic citations %% %\usepackage{amsmath} % Better maths support %\usepackage{ulem} % more underlining and other font effects %%usepackage{amssymb} % & more symbols %%\usepackage{bm} % Define \bm{} to use bold math fonts % %\usepackage[pdftex,bookmarks,colorlinks,breaklinks]{hyperref} % PDF hyperlinks, with coloured links %%\definecolor{dullmagenta}{rgb}{0.4,0,0.4} % #660066 %%\definecolor{darkblue}{rgb}{0,0,0.4} %\hypersetup{linkcolor=red,citecolor=blue,filecolor=dullmagenta,urlcolor=darkblue} % coloured links %%\hypersetup{linkcolor=black,citecolor=black,filecolor=black,urlcolor=black} % black links, for printed output % %%\usepackage{memhfixc} % remove conflict between the memoir class & hyperref %%% \usepackage[activate]{pdfcprot} % Turn on margin kerning (not in gwTeX) %%\usepackage{pdfsync} % enable tex source and pdf output syncronicity % % % %%%%% PAGE DIMENSIONS %\usepackage[marginparwidth=3cm, top=2cm, bottom=2cm, a4paper]{geometry} % for example, change the margins to 2 inches all round %%%\geometry{landscape} % set up the page for landscape %%% read geometry.pdf for detailed page layout information %\usepackage{lscape} % offers landscape environment, \begin{landscape} %% % %%%%% HEADERS & FOOTERS %\usepackage{fancyhdr} % This should be set AFTER setting up the page geometry %\pagestyle{fancy} % options: empty , plain , fancy %%%\renewcommand{\headrulewidth}{0pt} % customise the layout... %\lhead{Claudius Kerth} % alined left in header %\chead{\textbf{double digest sRAD protocol}} % alined centrically in header %\rhead{\today} % alined right in header %\usepackage{lastpage} % in order to call the number of the last page in the footer %\lfoot{} %\cfoot{} %\rfoot{\thepage ~of \pageref{LastPage}} %% %%%%% SECTION TITLE APPEARANCE %%%\usepackage{sectsty} %%%\allsectionsfont{\sffamily\mdseries\upshape} % (See the fntguide.pdf for font help) %%% (This matches ConTeXt defaults) %% %%%%% ToC APPEARANCE %%%\usepackage[nottoc,notlof,notlot]{tocbibind} % Put the bibliography in the Table of Contents %%%\usepackage[titles]{tocloft} % Alter the style of the Table of Contents %%%\renewcommand{\cftsecfont}{\rmfamily\mdseries\upshape} %%%\renewcommand{\cftsecpagefont}{\rmfamily\mdseries\upshape} % No bold! % % %% SET UP HYPERREF %\usepackage[pdftex,bookmarks,colorlinks,breaklinks]{hyperref} % PDF hyperlinks, with coloured links %%\definecolor{dullmagenta}{rgb}{0.4,0,0.4} % #660066 %%\definecolor{darkblue}{rgb}{0,0,0.4} %\hypersetup{colorlinks, %citecolor=black,% %filecolor=black,% %linkcolor=black,% %urlcolor=blue,% %pdftex} % % %% %\begin{document} %%%%%% TITLE %% %\title{Double-Digest sRAD protocol} % %% %% %\author{Claudius Kerth\\University of Sheffield\\Evolutionary biology group - Prof. Roger K Butlin\\email: \texttt{c.kerth@sheffield.ac.uk}} %%%double-shlash for line breaks %%% \texttt sets the letters in monospace font, might be interesting for typesetting DNA sequences %\date{\today} % tilde for no date, \today for current date %% %% %%\thispagestyle{plain} %% %% %%%%% BEGIN DOCUMENT %% %% %\maketitle %% %%%Because the maketitle command has just been used, it automatically %%%issues \thispagestyle{plain} which overrides the fancy headings for %%%this page. Must now tell Latex to override this! %% %% %%%\tableofcontents % uncomment to insert the table of contents %% % %\begin{abstract} %This protocol describes the procedure to prepare a double-digest RAD library from genomic DNA of 38 grasshoppers. Through digestion with two restriction enzymes and ligation of the P2 adapter to one type of the sticky ends as well as through gel size selection (issue of repeatability), this protocol achieves additional complexity reduction to the standard RAD protocol by Paul Etter (Oregon). It includes a normalisation step with double strand specific nuclease usually used for cDNA libraries (Evrogen). The normalisation is recommended when the selective PCR product contains distinct bands or is severely biased towards certain fragment lengths. %\end{abstract} %% %%\clearpage % inserts pagebreak, I think %% %% Requires the booktabs if the memoir class is not being used %% %% %%%\setlength{\columnsep}{20pt} % sets the distance between the text columns %%%\begin{multicols*}{2} % multicol package needs to be installed for this, sets the number of text columns per page to two %% %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%\twocolumn %% \graphicspath{ {/Users/Claudius/Documents/PhD/THESIS/kks32/LaTeX/Appendix1/} } \section{Double-Digest sRAD protocol} \label{ch:ddRAD_protocol} \subsection{ingredients} {\small \begin{itemize} \item silica membrane genomic DNA extraction kit (e. g. Qiagen Dneasy Blood and Tissue Kit) \item agarose \item fluorometer, Hoechst dye and standard solutions (e. g. Calf Thymus standard) \item SbfI High Fidelity from NEB \item EagI HF and AgeI HF from NEB \item thermal cycler \item 96-well PCR plates \item adhesive plate sealing film from qPCR machine \item plate centrifuge \item barcoded P1 adapters ( at 100nM concentration) \item P2Y adapter with complementary sticky ends to the 6bp cutter used (and optionally containing barcodes) \item \textbf{r}ATP (100nM concentration) \item concentrated T4 DNA ligase \item Qiagen MinElute reaction cleanup kit (Cat. no. 28204) \item Glycerol \item 6x OG \item TBE \item QG buffer \item SybrSafe \item Blue-light transilluminator \item razor blades \item SpeedVac (or just table centrifuge) \item Phusion PCR mastermix \item P1 and P2 PCR primer \item filter tips \item BioAnalyzer \item ethidium bromide \end{itemize} } % % \subsection{protocol} % % \subsection{isolate DNA from grasshopper hindleg} \begin{itemize} \item with Qiagen Dneasy Blood and Tissue Kit (spin columns) \end{itemize} \subsection{check the quality of the isolations} \begin{itemize} \item by running each isolation on a 1.0\% gel \end{itemize} %\begin{figure}[!htb] %\begin{center} %\includegraphics[scale=0.5]{DNAiso180410_cropped} %\caption{Four spin column DNA isolation from grasshopper hindlegs next to HindIII digested lambda. The DNA is obviously already fragmented. All grasshopper DNA isolations look like that. The sRAD protocol worked anyway fine with them.} %\label{DNAiso} %\end{center} %\end{figure} \subsection {quantify DNA samples with fluorometer twice} \begin{itemize} \item produce at least three replicates of calf thymus standard serial dilutions for the standard curve \item produce at least 5 points for the standard curve spanning from $\sim$200ng/$\mu$l to $\sim$12.5ng/$\mu$l \item remove dodgy measurements of the standard in order to increase $r^{2}$ to at least 0.99 \item get at least two concentration measurements per DNA isolation \end{itemize} \subsection {digest 132 ng of DNA from each individual with SbfI HF and XhoI} \begin{itemize} \item make master mix of 40$\times$: \begin{itemize} \item 3.0$\mu$l 10X NEBuffer 4 \item 3.0$\mu$l 10x BSA \item 0.5$\mu$l SbfI-HF (20 U/$\mu$l) $\rightarrow$ 10 U/sample $\rightarrow$ 72U/$\mu$g DNA \footnote{This requires 20$\mu$l of the 25$\mu$l SbfI enzyme in a tube of 500 U.} \item 0.5$\mu$l XhoI (20 U/$\mu$l) $\rightarrow$ 10 U/sample $\rightarrow$ 72U/$\mu$g DNA \item 10$\mu$l ddH$_{2}$O \end{itemize} \item based on the DNA measurements, adjust the amount of DNA isolation volume for the digestion, so that more or less equal amounts of each sample go into the library (see \texttt{Fluorimeter.ods}) \item fill with ddH$_{2}$O to 30$\mu$l endvolume \item the total amount of DNA from all samples should not exceed the capacity of a MinElute spin column (5$\mu$g). Otherwise, two separate libraries have to be prepared. \item in an Excel spreadsheet, enter the code and volume of each DNA isolation in a layout that corresponds to the 96 well plate, print it out and use it as reference when pipetting \item beware of cross-contamination, particularly when opening the lid of the plate \item mix by pipetting, shake the plate at the end, spin down with centrifuge \item incubate for 3 hours at 37$^{\circ}$C in a thermal cycler with heated lid \item heat-inactivate in thermal cycler at 65$^{\circ}$C for 20 min, then ramp down to room temperature at no more than 2$^{\circ}$C/min \footnote{adhesive films for qPCR plates only seal tight after heating via a heated lid beyond 70$^{\circ}$C} \end{itemize} \subsection {calculate the molar amount of sticky ends in the restriction digest} \begin{itemize} \item Parameters: \begin{itemize} \item genome size: $12\times10^{9}$bp \item average molecular weight of a base pair: 660$\frac{g}{mol\times bp}$ \item expected number of SbfI restriction sites per genome (GC 46.5\%): 135,633 \footnote{see \texttt{ComplexityReduction.xls} for the calculation of this number } \item amount of digested DNA in g per sample: $132\times 10^{-9}$g \end{itemize} \item SbfI sticky ends: % in order to be able to use the 'equation' environment you need to load the package 'amsmath' % load package 'ulem' for \uuline command \begin{align} \text{molar amount of SbfI sticky ends} &= \frac{\text{amount of DNA}}{\text{MW of bp} \times \text{genome size} } \times \text{SbfI sites per genome} \times 2 \\ \nonumber &= \frac{132\times 10^{-9}g}{660 \frac{g}{mol\times bp} \times 12\times10^{9} bp} \times 135,633 \times 2\\ \nonumber &= 4.52 \times 10^{-15} \text{mol}\\ \nonumber &= \uuline{4.52 \text{fmol per sample}} \end{align} \item XhoI sticky ends: \begin{itemize} \item expected number of XhoI restriction sites per genome (GC 46.5\%): \\ 2,509,115 \footnote{see \texttt{ComplexityReduction.xls} for the calculation of this number } $\rightarrow 18.5 \times \text{SbfI sites}$ \begin{align} \text{molar amount XhoI sticky ends} &= 18.5 \times \text{molar amount of SbfI sticky ends} \\ \nonumber &= 18.5 \times 4.52 \times 10^{-15} \text{mol} \\ \nonumber &= 83.6 \times 10^{-15} \text{mol} \\ \nonumber &= \uuline{83.6\text{fmol per sample}} \end{align} \end{itemize} \item in order to provide adapters in $\sim10-20 \times$ excess toward sticky ends, use 100fmol (=0.1pmol) P1 adapter per sample and 2pmole of P2 adapter per sample \end{itemize} \subsection {set up a 10$\mu$M P2Y-XhoI adapter stock solution from oligos} \begin{itemize} \item set up annealing buffer (AB) as shown in table \ref{AB} %\marginal{{\color{red}does this buffer contain a high enough salt concentration?!}} %\marginal{{\color{blue}yes, 1X NEB2 contains 50mM NaCL}} % call ctable package, \ctable[ caption = {annealing buffer set up:}, label = AB, pos = htb!, width = 70mm, % captionskip = -.5ex, % bring the caption closer to the table center ] {>{\raggedright}X>{\raggedleft}X} { \tnote{1x NEB2 contains 10mM MgCl$_{2}$} \tnote[b]{0.372g EDTA dissolved in 10ml 1x NEB2} } { \FL NEB2 (10x)\tmark & 100$\mu$l \NN EDTA (100mM)\tmark[b] & 110$\mu$l \NN ddH$_{2}$O & 790$\mu$l \ML & 1,000$\mu$l \LL } \item \dots split the volume into 100$\mu$l aliquots and heat them to 65$^{\circ}$ for 20 minutes \footnote{in order to denature nuclease contamination} \item spin down lyophilised oligos in manufacturers tube for 1 min at maximum speed \item dissolve the lyophilised oligos with EB to 100$\mu$M \item then set up 10$\mu$M adapter solution with: \ctable[ caption = { }, % label = , pos = h, width = 80mm, % captionskip = -.5ex, % bring the caption closer to the table center ] {>{\raggedright}X>{\raggedleft}X} { } { \FL upper oligo (100$\mu$M) & 10$\mu$l \NN lower oligo (100$\mu$M) & 10$\mu$l \NN AB & 80$\mu$l \ML & 100$\mu$l \LL } \item \ldots and anneal the oligos by heating the mixture in the thermal cycler to 96$^{\circ}$C for 2 minutes and then ramping down to RT at 2$^{\circ}$/min \end{itemize} \subsection {ligate adapters to each restriction digest} \begin{itemize} \item put the sample plate on ice \item thaw P1 adapter plate on ice, shake to mix, spin down, reseal the plate after use \item first add to each heat inactivated restriction digest: \begin{itemize} \item 1.0 $\mu$l of 100nM barcoded P1 adapter $\rightarrow$ 0.1 pmol \footnote{0.757pmole/$\mu$g DNA; 22 fold excess of adapter to cohesive ends. If you size select at 300bp or above, adapter dimers shouldn't be a problem.} \item 2.0 $\mu$l of 1$\mu$M P2-XhoI adapter $\rightarrow$ 2.0 pmol \footnote{15 pmol/$\mu$g DNA; 23.9 fold excess of adapter to cohesive ends.} \end{itemize} \item vortex plate and spin down \item then make master mix of 40$\times$: \begin{itemize} \item 0.8 $\mu$l 10X NEB Buffer 2 \footnote{adds 10mM NaCl to the final solution, final NaCl concentration $\sim$50mM, which is necessary to keep the P2Y adapter double stranded; however, salt concentrations of 100mM decrease ligation efficiency (from NEB FAQ)} \item 0.4 $\mu$l \textbf{r}ATP (100mM $\rightarrow$ end concentration 1 mM) \footnote{rATP powder dissolved in EB (pH 8.5) is stable; reduce freeze-thawing cycles; 0.1 mM ATP is as efficient as 1mM but a 10mM ATP concentrations inhibit ligations!} \item 0.2 $\mu$l concentrated T4 DNA Ligase (2,000 NEB U/$\mu$l) \footnote{400U/sample corresponding to 3030 NEB U/$\mu$g DNA} \item 5.6 $\mu$l ddH$_{2}$O \end{itemize} \item add 7.0 $\mu$l of master mix to each well to a 40$\mu$l end volume and mix by pipetting up and down \item after carefully sealing the plate with adhesive film, vortex and spin down \item final monovalent cation concentration should be $\sim$50 mM \footnote{NEBuffer 4 contains 50mM potassium ions} \item incubate at room temperature (RT) for 2 hours, then over night in the fridge \item heat-inactivate at 65$^{\circ}$C for 20 min in thermal cycler, then ramp down to RT at 2$^{\circ}$C/min \end{itemize} \subsection {combine samples} \begin{itemize} \item pool the 38 individual ligation mixes, making up $\sim$1,520$\mu$l and $\sim$5 $\mu$g DNA \end{itemize} %%%%% ctable - for tables with footnotes. Very useful. % call ctable package, %\ctable[ % caption = optimal Covaris settings, % label = Covaris, % pos = h, % width = 55mm, % captionskip = -2ex, % bring the caption closer to the table % center %] %{>{\raggedright}X>{\raggedleft}X} %{} %{ %\FL %duty cycle & 10\% \NN %intensity & 5 \NN %cycles/burst & 200 \NN %duration & 100sec %\LL %} %\item optimal Covaris settings: %\begin{tabular}{lr} %\hline \addlinespace[.5em] %duty cycle &10\%\\ %intensity &5\\ %cycles/burst &200\\ %duration &100sec\\ %\addlinespace[.5em] \hline %\end{tabular} %\end{itemize} \subsection {clean up and concentrate the adapter ligated library} \begin{itemize} \item with one Qiagen MinElute reaction cleanup column (Cat. no. 28204), capacity each 5$\mu$g DNA\footnote{ignore what the kit manual says about the maximum amount of enzymatic reaction that can be cleaned up per column} \item use at least as much ERC buffer as ligation mix for the reaction cleanup kit \item elute with 15 $\mu$l EB \end{itemize} \subsection {size selection on agarose gel}\label{sizeSelection} \begin{itemize} \item rinse the gel tank and use fresh buffer before running the gel\footnote{if you have run a gel from a different library before, otherwise not necessary} \item make a 110ml 1\% TBE gel with 6.3$\mu$l SybrSafe \item add 10$\mu$l 6x OG loading dye and $\sim$5$\mu$l 100\% Glycerol to the 15$\mu$l eluate of the last step \footnote{$\sim$5$\mu$g DNA per lane, the glycerol is necessary to make the DNA sink into the gel well, a lot of DNA could otherwise be lost at this step} \item run the whole mix in one lane at 13 V/cm for $\sim$45 min or when the orange dye just about reaches the bottom of the gel \item the wells should be less than half full, otherwise migration of fragments will be distorted $\rightarrow$ 5--6mm wide wells \item load 30$\mu$l 100bp ladder (50ng/$\mu$l) in the left lane, leave 1 lane space between standard and library \item use fresh razor blade and a blue light transilluminator to cut out a size range of $\sim$300-800 bp (fig. \ref{SizeSel}) \footnote{be as accurate as possible with the vertical cuts, you can take your time, be sure not to go below 300bp, otherwise risk of adapter dimer contamination (Maureen Liu)} \item cut the gel block into 4 pieces and put each into a 2ml tube \item weigh each tube and subtract the weight of an empty tube to get the gel weights in mg \item add $3 \times$ as much buffer QG to each tube as the weight of its gel piece \item rotate the tubes at RT for one hour to melt the gel pieces \item combine the dissolved gel pieces in a bigger vessel and add one gel volume (mg=ml) of isopropanol followed by mixing \item purify that solution over one MinElute spin column with a SpeedVac \footnote{even though it says otherwise in the manual of the kit, you can gel extract with just one column as long as the gel contains no more than 1\% agarose and it is completely melted before loading} \item elute with 30$\mu$l EB \end{itemize} % \begin{figure}[htb] \begin{center} \includegraphics[scale=0.3]{GelSizeSelection_071011} \caption{Gel picture after size selection.} \label{SizeSel} \end{center} \end{figure} %\begin{figure}[!htb] %\begin{center} %\subfigure[two pools sheared with the Covaris settings from Table \ref{Covaris}]{\label{shearedPools}\includegraphics[scale=0.32]{shearedPools_180610_1}} %\hfill %\subfigure[after size selection of the pools]{\label{shearedPools}\includegraphics[scale=0.3]{sizeSelection_after_250610}} %\caption{Size selection of fragments after shearing.} %\label{shearedPools} %\end{center} %\end{figure} \subsection {selective amplification} \label{selAmp} \begin{itemize} \item save 6$\mu$l of the eluate of the last step for later qPCR \item then set up a PCR with the remaining 24$\mu$l eluate: \begin{itemize} \item 6.0 $\mu$l H2O \item 50.0 $\mu$l 2x Phusion Mastermix \footnote{Do not use Phusion PCR kit with standard dNTP's. Phusion only works with high quality dNTP's !} \item 10.0 $\mu$l P1-thiol primer (10$\mu$M) $\rightarrow$ 1.0$\mu$M end concentration \footnote{I found that a much higher primer concentration than usual can greatly increase yield} \item 10.0 $\mu$l P2-thiol primer (10$\mu$M) \item 24 $\mu$l RAD library template \end{itemize} \item split the PCR mix into 5x 20$\mu$l volumes and add 10$\mu$l mineral oil to each PCR tube \item then run each tube with the PCR programme shown in table \ref{selPCR} %%%%% ctable - for tables with footnotes. Very useful. % call ctable package \ctable[ caption = PCR programme, label = selPCR, pos = h, width = 45mm, center ] {>{\centering}X>{\raggedright}X>{\raggedright}X} { \tnote{30sec per kb recommended} } { \FL 98$^{\circ}$ & 30sec & \ML 98$^{\circ}$ & 10sec & \multirow{3}{*}{\Huge{$\}$}\normalsize$\times$18} \NN 65$^{\circ}$ & 30sec & \NN 72$^{\circ}$ & 30sec\tmark[a] &\ML 72$^{\circ}$ & 5min & \NN 4$^{\circ}$ & $\infty$ & \LL } \end{itemize} \subsection {purifcation and concentration of the selective PCR product} \begin{itemize} \item {\color{red}use filter-tips or different pipettes for anything post-PCR !} \item combine all PCR products and check 5$\mu$l of it on a 1.25\% gel next to 2$\mu$l Genruler \item take 6$\mu$l of the PCR product for qPCR \item purify the rest of the PCR product over a MinElute column eluting with 10$\mu$l EB \end{itemize} \subsection {determination of template amount used for selective PCR by qPCR} \begin{itemize} \item {\color{red}use filter-tips} \item use 4$\mu$l of the 6$\mu$l of the PCR product set aside in the previous step to determine it's DNA concentration with the fluorometer and picoGreen dye and use it as a standard in the qPCR \item make 8x 1:10 serial dilutions of the PCR product in 10$\mu$l EB each to produce a standard curve \item set up 20$\mu$l qPCR reactions with SybrGreen PCR master mix and 2$\mu$l template: \begin{itemize} \item three replicates of serial dilutions including negative control \item three replicates of the template saved in step \ref{selAmp} \end{itemize} \item from the C$_{t}$ values and the known amount of template molecules in the standard dilution, determine the amount of template molecules per locus and individual \footnote{This can be used to predict the expected proportion of false homozygote genotype calls due to PCR drift and false heterozygote genotype calls due to high coverage PCR mutations.} \\(see \texttt{sRAD/qPCR/TRIAL\_LIB\_241011\_data.xls}) \end{itemize} \subsection {normalisation of the library} Unless the library looks like a homogeneous smear on the gel, it is advisable to normalise it. \begin{itemize} \item check activity of double strand specific nuclease (DSN) with control template from the kit \item {\color{red}use filter-tips} \item take 6$\mu$l of the purified PCR product and add 2$\mu$l 4x Hybridization buffer \footnote{500mM final NaCl concentration for annealing. EB contains 10mM Tris-HCl at pH 8.5, 1x hybridization buffer contains 50mM HEPES at pH 7.5. So the pH in the mixture should be close to 7.5.} \item put 4$\mu$l of the mixture in each of two tubes, labeled ``1/8'' and ``1/16'' \item overlay the reaction mixtures with 10$\mu$l mineral oil and spin down for 2 min at max speed \item in a thermal cycler, heat the mixture to 98$^{\circ}$ for 2 min \item \ldots then incubate at 68$^{\circ}$ for 5 hours \item put DSN master buffer into thermal cycler to preheat it to 68$^{\circ}$ \item make a 1/8th and 1/16 dilution of the DSN enzyme with DSN storage buffer \item keep the thermal cycler at 68$^{\circ}$C and add 5$\mu$l preheated DSN master buffer to each tube while keeping the tube in the cycler, then flick, spin down briefly and immediately put back into the thermal cycler \item incubate for 10 minutes at 68$^{\circ}$C \item add 1$\mu$l of 1/8th or 1/16th DSN enzyme into each tube respectively \footnote{just add the enzyme, don't flick, don't spin down, just be quick, i. e. no more than 10 seconds for this step!} \item incubate for 25 minutes at 68$^{\circ}$C \item add 10$\mu$l DSN stop solution, mix and spin \footnote{the reaction mixture contains 5mM MgCl$_{2}$ and the stop solution contains 5mM EDTA to neutralise it. Figure 4(B) in the TRIMMER kit manual suggests that inactivation of DSN by heating is not guaranteed to be complete.} \end{itemize} \subsection {test PCR of normalisation} \begin{itemize} \item {\color{red}use filter-tips} \item from each vial of the last step (i. e. ``1/8'' and ``1/16''), set up three 10$\mu$l test PCR's with 1$\mu$l template \item run PCR for 5, 10 and 15 cycles with temperature steps as in table \ref{selPCR} and check 5$\mu$l PCR product on a 1.25\% EtBr gel next to 2$\mu$l Genruler \item examine the PCR product: homogeneous smear in right size range?, 5 cycle PCR product visible? (see figure \ref{NormTestPCR}) \begin{figure}[!htb] \begin{center} \includegraphics[scale=0.4]{Normalisation_test_lib_PCR_28072011} \caption{Gel picture of 5, 10 and 15 cycle test PCR's (from left to right).} \label{NormTestPCR} \end{center} \end{figure} \item decide which DSN dissolution produced the better result \end{itemize} \subsection {amplification of normalised library} \begin{itemize} \item {\color{red}use filter-tips} \item set up a 50$\mu$l PCR as follow: \begin{itemize} \item 25$\mu$l 2x Phusion Master mix \item 5$\mu$l P1-thiol primer (10$\mu$M) \item 5$\mu$l P2-thiol primer (10$\mu$M) \item 10$\mu$l normalised library \item 5$\mu$l ddH$_{2}$O \end{itemize} \item run the PCR programme in table \ref{selPCR} for 5-7 cycles, depending on the outcome of the test PCR \footnote{These additional PCR cycles do not further bias the library's representation of the pre-normalisation template since this PCR starts with a lot of template molecules as indicated by the few cycles necessary to create a visible PCR product.} \end{itemize} \subsection {purification of the library} \begin{itemize} \item {\color{red}use filter-tips} \item purify the 50$\mu$l PCR product over a MinElute column \item elute with 25$\mu$l EB \item use 4$\mu$l for DNA concentration measurement with fluorometer \item calculate an estimate of the molar concentration of the library \end{itemize} %\begin{figure}[!htb] %\begin{center} %\includegraphics[scale=0.5]{selPCR_260610_cropped} %\caption{PCR products of test amplifications of two libraries left of their respective templates. Adapter dimers are visible at $\sim$130bp.} %\label{testAmp} %\end{center} %\end{figure} %\subsubsection %{perform a 100$\mu$l PCR} %\begin{itemize} %\item with 4$\mu$l template if very strong PCR product from test PCR, otherwise up to 30$\mu$l template %\item 18 PCR cycles only in order to minimize PCR duplicates and bias %\item purify the PCR product with Qiagen MinElute PCR purification column, elute with 20$\mu$l %\item use filter-tips for anything post-PCR ! %\end{itemize} % %\subsubsection %{gel purification of amplified library} %\begin{itemize} %\item use filter-tips for anything post-PCR ! %\item rinse the gel tank and use fresh buffer before running the gel if you have run a different library before %\item run elution (20$\mu$l) in one lane of 1.25\% agarose gel with 10 $\mu$l 6X Orange Dye for 1h 15 min at 6.7 V/cm %\item the wells should be less than half full, otherwise migration of fragments will be distorted \footnote{5--6mm wide wells} %\item load 20$\mu$l 100bp ladder (20$\mu$g) in the left lane, leave 1 lane space between standard and library %\item use fresh razor blade and UV transilluminator (long wave setting to minimize mutations) to cut out a size range of $\sim$350-750 bp \footnote{adapter dimers run at $\sim$130bp, when making the vertical cuts, be sure not to go below 350bp, otherwise risk of adapter dimer contamination (Maureen Liu)} %\end{itemize} % %%\begin{figure}[!ht]%a picture has to be inserted into a figure environment in order to make it floatable; a star at figure has to be added for a two column layout %%\begin{center} %%\subfigure[before size selection]{\label{before}\includegraphics[scale=0.5]{selPCR_040710_gel_before_cropped}} %%\hfill %pushes the graphics to the left and right margins %%\subfigure[after size selection]{\label{after}\includegraphics[scale=0.5]{selPCR_040710_gel_after}} %%\end{center} %%\caption{Size selection of the amplified RAD library. Adapter dimer bands are clearly visible. About $\sim$0.03\% of the reads from this library came from adapter dimers or sequences with very small genomic inserts.} %%\label{sizeSelection2}%the label command has to occur after the caption but inside the figure environment to refer (with \ref) to the figure and not the section of the document %%\end{figure} % % %\subsubsection %{gel extraction} %\begin{itemize} %\item filter-tips ! %\item with MinElute Gel Extraction Kit %\item melt agarose slice at room temperature with frequent mixing %\item elute in 20 $\mu$l EB %\end{itemize} % % % %\subsubsection %{quantify molar concentration of RAD tags} %\begin{itemize} %\item determine DNA concentration of the library with fluorimeter twice and each with at least 3 replicates of the calf thymus standard serial dilution %\item determine size distribution and peak size of RAD tags with Agilent Bioanalyzer 2100 DNA chip or from agarose gel picture %\item multiply peak size by 650 [g/mol] \footnote{the molecular weight of a base pair} to get the molecular weight of the library %\item divide the DNA concentration of the library [g/$\mu$l] by it's molecular weight to get the molar concentration [nmole/L] of RAD tags in the library %\end{itemize} % \subsection {validate library \protect \footnote{optional because of the cost and effort involved with cloning, but recommended before spending a lot of money on Solexa sequencing}} \begin{itemize} \item A-tail PCR product \item T/A clone 1.0 $\mu$l of library into pGEM vector \item Sanger sequence a few dozen clones \item check for whether the sequences contain a P1 adapter sequence on one end and a P2 adapter sequence on the other %\item also check for the frequency of PCR duplicates among the clones\footnote{when P2Y adapter is at the same position in two clone sequences} and blast the sequences \end{itemize} \pagebreak %\begin{landscape} % %\ctable[ % caption = {comparison among different ddRADseq protocols}, % label = compProt, %% pos = htb!, %% sideways, % width = 240mm, % captionskip = 1ex, % bring the caption closer to the table % doinside=\footnotesize, % center, %] %{l>{\raggedright}X>{\raggedright}X>{\raggedright}X>{\raggedright}X>{\raggedright}X>{\raggedright}X>{\raggedright}X} %{ %} %{ %\FL %\textbf{protocol} & \textbf{adapters} & \textbf{DNA isolation} & \textbf{digestion} & \textbf{ligation} & \textbf{gel size selection} & \textbf{PCR} & \textbf{purification} %\ML %\cite{Peterson2012} & P1 and P2 adapter at stock conc. of 40$\mu$M, short adapters and long PCR primers & NA & digest for 3h, no heat-inact. -- instead bead puri. & 30min ligation at RT, 2-10 fold excess of adapters to sticky ends & before PCR, automated DNA size selection with Pippin-Prep (Sage Science) & 20ng size-selected library per PCR reaction, 2$\mu$M end conc. of each PCR primer, only 8-12 cycles (?!) & AMPure beads \NN % the ``\rowcolor'' command requires the ``colortbl'' packageted %\rowcolor[gray]{0.9} \cite{Andolfatto2011} & 10$\mu$M stock conc., short adapters + long PCR primers & Puregene (Qiagen) & 10ng DNA per sample, with 3.3U of 4bp cutter MseI (i. e. no double-digerst), 3h at 37$^{\circ}$C followed by heat-inact. & 5nmole adapters, only 1 U of T4 DNA ligase in a volume of 50$\mu$l, 1h at 16$^{\circ}$C & before PCR, ladder mixed into library, 2\% gel & only 15 cycles, Phusion & AMPure beads \NN %\cite{Parchman2012} & 1$\mu$M stock conc. for P1 (EcoRI) adapter, % 10$\mu$M stock conc. for P2 (MseI) adapter, % annealing in pure water (?!), % short adapters + long PCR primers & NA & 6- and 4bp cutter, 10U EcoRI, only 1U MseI, digestion in T4 buffer, % NaCl added to $\sim$50mM end conc., % volume 9$\mu$l, 8h, heat-inact. & 1pmole EcoRI adapter, 10pmole MseI adapter, % 67 NEB units T4 ligase, 6h at 16$^{\circ}$C, % ligation in only 11.4$\mu$l & after PCR, 2.5\% gel, low electric field gel runs, % EtBr gels, many lanes & individual PCR before pooling samples and before gel size selection, % 30 cycles (?!), only 0.08$\mu$M end conc. of each primer in PCR (?!), % BioRad Iproof High Fidelity DNA polymerase & QiaQuick spin columns \NN %\rowcolor[gray]{0.9} Kerth et al. (2030) & & & & & & &\NN %\LL %} % %\end{landscape} %\bibliographystyle{apalike} %\bibliography{/Users/Claudius/Documents/MyLiterature/Literature} % %\begin{enumerate} %\item Implement a new random genetic marker technique called \textit{sRAD}. %\item Find loci linked to Dobzhansky-Muller incompatibilities responsible for sterility in F$_{1}$ male hybrids of two grasshopper subspecies. %\end{enumerate} % %\begin{itemize} %\item How many genes are responsible for the observed hybrid male sterility? %\item Are these genes disproportionately located on the X-chromosome? %\end{itemize} % % %\subsubsection{Background} %Two subspecies of \emph{Chorthippus parallelus} -- \emph{Chorthippus parallelus parallelus} and \emph{C. p. erythropus} -- form a hybrid zone in the Pyrenees. F$_{1}$ male hybrids between \emph{C. p. parallelus} and \emph{C. p. erythropus} from outside the hybrid zone are almost completely sterile with degenerate testes and a severely disrupted meiosis \citep{Hewitt1987} %$\sim$1800 RAD tags % \textsterling1,100. %(see section \ref{QTL cross} on p. \pageref{QTL cross}), %\citep[p. 284-319]{CoyneOrr2004}, such as: % % %\begin{figure*}[htb]%a picture has to be inserted into a figure environment in order to make it floatable; a star at figure has to be added for a two column layout %\begin{center} %\subfigure[Oscillogramm (bottom) and traces of the corresponding hindleg movements (top) of a singing \emph{C. montanus} male. Three syllables are shown. (from \citealp{Helversen1994}, p. 271) ]{\label{montanus}\includegraphics[scale=1.0]{montanus}} %\hfill %pushes the graphics to the left and right margins %\subfigure[Syllable duration over body temperature in \emph{C. parallelus} (syn. \emph{longicornis}) and \emph{C. montanus} males. (from \citealp{Helversen1987}, p. 121)]{\label{syllable}\includegraphics[scale=1.2]{syllableDuration}} %\end{center} %\caption{The songs of \emph{C. montanus} and \emph{C. parallelus} differ only in the duration of their syllables.} %\label{songdiff}%the label command has to occur after the caption but inside the figure environment to refer (with \ref) to the figure and not the section of the document %\end{figure*} % % % %%%% sRAD sketch from Floragenex website %\begin{figure*}[tbp] %\begin{center} %\includegraphics[scale=.25]{RADprocessOverview} %\caption{\emph{sRAD} is basically Solexa/illumina sequencing of restriction fragment ends. Each restriction site defines the position of two tightly linked RAD tags.} %\label{Floragenex} %\end{center} %\end{figure*} %%%% % %\underline{s}equenced \underline{R}estriction \underline{S}ite associated \underline{D}NA. % %50\% NERC funding % % % % % %%%% my own sketch of the sRAD library preparation process %\begin{figure*}[htbp] %\begin{center} %\includegraphics[scale=.6]{sRADprocessSketch} %\caption{(a) The genome is cut but a restriction endonuclease ~~(b) P1 adapters (blue) containing a different 5base pair long nucleotide sequence (red) for each individual sample are ligated to restriction fragment ends. ~~(c) After pooling the P1 ligated samples, they are sheared to below 1kb before a size range is selected on the gel. The shearing step makes the marker technique repeatable. ~~(d) A few steps further, the P2 adapter, a divergent Y adapter, is ligated onto all fragments. In the following PCR, only fragments with at least one P1 adapter will be amplified. ~~(e) Further complexity reduction by restricting the library with frequent cutter restriction enzymes. ~~(f) Solexa sequencing. The first 5 base pairs in the reads identify the individual. A T/A single nucleotide polymorphism is marked by the red frames.} %\label{sRADsketch} %\end{center} %\end{figure*} %%%% % % %\begin{quotation} %``\ldots the most important determinant of [QTL analysis] power is F2 and/or backcross sample size \ldots small samples sizes lead to systematic overestimation of QTL addititive effects, the so-called \textsc{beavis} effect \ldots simulations suggest that this effect becomes small as experimental sample sizes near $\sim$500 genotyped and phenotyped individuals.'' \citep{Orr2001a} %\end{quotation} % %The temperature curve in the CT room where the grasshoppers have been recorded is oscillating by 2$^{\circ}$C % % % %%%%%%%% PCA table %% Requires the booktabs package if the memoir class is not being used %\begin{table}[!htbp] %\begin{center} %\topcaption{correlation of peaks with PCA scores} % requires the 'topcapt' package %\begin{tabular}{@{}lcr@{}} %\toprule %& \multicolumn{2}{c}{scaling by:}\\ %& Peak & Individual\\ %\cmidrule(l){2-3} % Partial rule. (r) trims the line a little bit on the right; (l) & (lr) also possible %& Comp.1 & Comp.1\\ %\midrule %Peak.1 & -0.8809&-0.8237\\ %Peak.2 & -0.8249&-0.8490\\ %Peak.3 & -0.7623&-0.8563\\ %Peak.4 & -0.8255&-0.6677\\ %Peak.5 & -0.8886&-0.5243\\ %Peak.6 &-0.4218&0.3017\\ %Peak.7 &-0.8427&0.1139\\ %Peak.8 &-0.6538&0.4732\\ %Peak.9 &-0.9358&0.3918\\ %Peak.10&-0.7138&-0.3078\\ %Peak.11 &-0.7750&0.1455\\ %Peak.12& -0.8784&-0.4255\\ %Peak.13 &-0.8469&0.1801\\ %Peak.14 &-0.8413&0.5327\\ %Peak.15 &-0.8619&0.5204\\ %Peak.16 &-0.8038&0.4222\\ %Peak.17 &-0.8171&0.2868\\ %Peak.18 &-0.8320&0.4565\\ %Peak.19 &-0.8707&0.6411\\ %Peak.20 &-0.8834&0.6679\\ %Peak.21 &-0.8377&0.6844\\ %Peak.22& -0.8207&0.6334\\ %Peak.23 &-0.7635&0.5860\\ %\bottomrule %\end{tabular} %\label{PCcorrPeak} %\end{center} %\end{table} %%%%%%% PCA table % % % %\begin{table*} % the asterisk puts the table on that page, I don't know why, but here it fits better %\centering %\topcaption{MANOVA results for species difference of CHC blends among females using data scaled by peak.} % the top caption needs to be before the begin{tabular} command %\begin{tabular}{@{}lrrrrrr@{}} %\toprule %& \small{Df} & \small{Pillai} & \small{approx F} & \small{num Df} & \small{den Df} & {Pr($>$F)}\\ %\midrule %\small{Species} & \small{1} & \small{0.817} & \small{6.19} & \small{23} & \small{32} & \small{1.9e-06***}\\ %\small{Residuals} & \small{54} & & & & & \\ %\bottomrule %\end{tabular} %\label{manova} %\end{table*} % % % %%%%% multivariate outlier individuals %\begin{table}[!htbp] %\centering %\topcaption{Multivariate outlier individuals.} % requires the 'topcapt' package %\begin{tabular}{@{}lr@{}} %\toprule %Individual & $\sqrt[2]{Mahanalobis}$\\ %\midrule %26parF & 7.066\\ %49parF & 7.025\\ %50parF & 5.999\\ %52parF & 7.186\\ %53parF & 5.976\\ %55parF & 6.740\\ %85parF & 6.819\\ %29monF\underline{}Fin & 6.349\\ %32monF\underline{}Fin & 6.059\\ %84monF\underline{}Fin & 6.871\\ %61monF\underline{}Ger & 5.938\\ %\bottomrule %\end{tabular} %\label{outlier} %\end{table} % % % %\bibliographystyle{apalike} %\onecolumn %\setlength{\columnsep}{20pt} %\begin{multicols}{2} %% the separation of the columns has been set in the preambel %%\begin{multicols}{2} % %\bibliography{/Users/Claudius/Documents/MyLiterature/Literature} % %\end{multicols} % %\end{document}
\filetitle{assign}{Assign parameters, steady states, std deviations or cross-correlations}{model/assign} \paragraph{Syntax}\label{syntax} \begin{verbatim} [M,Assigned] = assign(M,P) [M,Assigned] = assign(M,Name,Value,Name,Value,...) [M,Assigned] = assign(M,List,Values) \end{verbatim} \paragraph{Syntax for fast assign}\label{syntax-for-fast-assign} \begin{verbatim} % Initialise assign(M,List); % Fast assign M = assign(M,Values); ... M = assign(M,Values); ... \end{verbatim} \paragraph{Syntax for assigning only steady-state levels}\label{syntax-for-assigning-only-steady-state-levels} \begin{verbatim} M = assign(M,'-level',...) \end{verbatim} \paragraph{Syntax for assignin only steady-state growth rates}\label{syntax-for-assignin-only-steady-state-growth-rates} \begin{verbatim} M = assign(M,'-growth',...) \end{verbatim} \paragraph{Input arguments}\label{input-arguments} \begin{itemize} \item \texttt{M} {[} model {]} - Model object. \item \texttt{P} {[} struct \textbar{} model {]} - Database whose fields refer to parameter names, variable names, std deviations, or cross-correlations; or another model object. \item \texttt{Name} {[} char {]} - A parameter name, variable name, std deviation, cross-correlation, or a regular expression that will be matched against model names. \item \texttt{Value} {[} numeric {]} - A value (or a vector of values in case of multiple parameterisations) that will be assigned. \item \texttt{List} {[} cellstr {]} - A list of parameter names, variable names, std deviations, or cross-correlations. \item \texttt{Values} {[} numeric {]} - A vector of values. \end{itemize} \paragraph{Output arguments}\label{output-arguments} \begin{itemize} \item \texttt{M} {[} model {]} - Model object with newly assigned parameters and/or steady states. \item \texttt{Assigned} {[} cellstr \textbar{} \texttt{Inf} {]} - List of actually assigned parameter names, variables names (steady states), std deviations, and cross-correlations; \texttt{Inf} indicates that all values has been assigned from another model object. \end{itemize} \paragraph{Description}\label{description} \paragraph{Example}\label{example}
\documentclass{amia} \usepackage{graphicx} \usepackage[labelfont=bf]{caption} \usepackage[superscript,nomove]{cite} \usepackage{color} \usepackage{enumitem} \usepackage{setspace} \usepackage{graphicx} \usepackage{subcaption} \usepackage{amsmath, amsthm} \usepackage{booktabs} \RequirePackage[colorlinks]{hyperref} \usepackage[lined,boxed,linesnumbered,commentsnumbered]{algorithm2e} \usepackage{xcolor} \usepackage{listings} \usepackage[utf8x]{inputenc} \usepackage{float} \begin{document} \title{Chest X-Ray (CXR) Disease Diagnosis with DenseNet} \author{Doug Beatty, Filip Juristovski, Rushi Desai, Mohamed Abdelrazik} \institutes{ Georgia Institute of Technology, Atlanta, Georgia\\ } \maketitle \noindent{\bf Abstract} \textit{Chest X-ray imaging \cite{ref1} is a crucial medical technology used by physicians to diagnose disease and monitor treatment outcomes. Training a human radiologist is a lengthy and costly process. Deep learning techniques combined with availability of larger data sets increases the feasibility of building automated models with performance approaching human radiologists.} \textit{We present a scalable deep learning model trained on the ChestXray14 \cite{ref7} data set of X-ray images to detect and correctly classify presence of 14 thoracic pathologies. We tried to beat current state of the art performance of models, and in some cases we were able to succeed. Class activation heatmaps are included which highlight areas of localization for the pathology in the image.} \section*{Introduction} A chest radiograph\cite{ref1}, or a chest X-ray (CXR) is one of the oldest and most common forms of medical imaging. A human radiologist requires significant training time and cost to be able to perform a comprehensive chest X-ray analysis with minimal error. Several types of abnormalities can arise in a chest radiograph that helps lead to detection and diagnosis of a multitude of diseases. With the vast number of different abnormalities and the overlapping reasons that might cause them, human error becomes a major contribution to poor diagnosis. The revolution of machine learning and deep learning techniques combined with the availability of larger data sets\cite{ref2} and big data processing systems\cite{ref3} makes the analysis of X-ray images increasingly more realistic and the creation of automated models more feasible. The objective of this project is to train an efficient and scalable deep learning model based off of DenseNets\cite{ref4}, which can learn from a data set of X-ray images to detect and correctly classify 14 different pathologies. Automating the X-ray analysis makes the overall diagnosing process faster and less error-prone which significantly improves a patient’s treatment procedure. \section*{Approach} Our approach consists of 5 high-level activities: \begin{enumerate} \item Data acquisition \item Image preprocessing - Apache Spark \item Training DenseNet-121 deep learning model - Keras + PyTorch \item Model validation and fine tuning \item Model evaluation \end{enumerate} The details of each of these activities are covered in subsequent sections. \section*{Data acquisition} Two different datasets were considered for chest radiographs. The first is ChestXray14 from the NIH, the current results of this paper utilize the ChestXray14 dataset. The second is CheXpert, which provides a substantial improvement to ChestXray14 with more training images and labels. CheXpert was initially planned on being used to further improve performance, but due to rising costs of training the model, it was not pursued. The full ChestXray14 dataset consists of 112,120 chest radiographs of 30,805 patients. The current model is trained off ChestXray14 and in some cases outperforms comparing models in performance for select pathologies. CheXpert\cite{ref2} consists of 224,316 chest radiographs of 65,240 patients. Each imaging study can pertain to one or more images, but most often are associated with two images: a frontal view and a lateral view. Images are provided with 14 labels derived from a natural language processing tool applied to the corresponding free-text radiology reports. \section*{Data Information} ChestXRay14 has high resolution images which are not suitable as input to the model. Using a high resolution image significantly increases the number of input feature vectors increasing overall model complexity and training time. Using a pretrained DenseNet model which was trained on ImageNet also required using the same dimension inputs. Data set images were preprocessed before training using Apache Spark which is a scalable big data processing technology. The dataset was stored in Google Cloud Storage to provide a scalable mechanism for handling the large data set. Several down-sampling techniques were used to reduce image size. A convolution neural network (CNN) is said to have an invariance property when it is capable to robustly classify objects even if its placed in different orientations. To enrich the input data set and increase the number of available training samples, horizontal flipping was applied randomly to images. This follows the DenseNet paper which found performance increases by adding horizontal flipping to the dataset. Each input image is down sampled by resizing to 224x224 pixels. An input image generates one or more augmented versions of itself (e.g. by horizontal flipping). The DenseNet model utilizes transfer learning, and was originally trained on the ImageNet dataset, because of this the training data was normalized by the mean and standard deviation of the ImageNet dataset. Some elementary statistics were gathered of the ChestXray14 dataset, this may be seen in Figure \ref{figd}. Class imbalances become prominent when looking at this chart, Hernia only compromises of 0.28\% of the total sample size, and Pneumonia only consists of 1.67\%. Further data pre-processing could be done to address these class imbalances such as re-sampling the data set to get more even distributions and adjusting class weights when training the model. \\ \begin{figure}[H] \centering \includegraphics[scale=0.35]{amia_template/pics/classDist.png} \caption{ChestXray14 Data Distribution} \label{figd} \end{figure} \section*{Method} Residual Networks (ResNets) allow us to train much deeper networks than a conventional CNN architecture since they handle the vanishing/exploding gradient problem much more effectively by allowing early layers to be directly connected to later ones. Dense Convolution Networks (DenseNets) are a form of residual network. Theoretically, it is expected that performance of models should increase as architecture grows deeper, but in reality as the network gets deeper, the optimizer finds it increasingly difficult to train the network due to the vanishing/exploding gradient problem. ResNet allow us to match the expected theoretical issue. ResNets have significantly more parameters than conventional CNN networks. DenseNet retains all features of ResNet and goes further by eliminating some pitfalls of ResNet. DenseNets have much less parameters to train compared to ResNets (typically up to 3x less parameters). You may refer to Figure \ref{figx} which shows how DenseNet layers are connected. By concatenating all layer outputs together, the DenseNet helps solve the vanishing gradient problem as gradients no longer pass through arbitrarily deep convolutional towers. Instead each component is directly connected with other layers, which reduces overall parameters since redundant feature maps are not learned and better representational learning between layers occurs. One of the main insights between DenseNets and ResNets is that DenseNets concatenate features between layers, compared to ResNets which uses a summation. This dense connectivity pattern is the primary reason why less feature parameters are usually required for DenseNets. \\ \begin{figure}[!htb] \centering \includegraphics[scale=0.2]{amia_template/pics/dense_net.png} \caption{DenseNet Layers} \label{figx} \end{figure} \\ The DenseNet models trained on ImageNet have a depth of 121. The architecture consists of a convolutional+pooling layer followed by 4 dense block stages. The dense block stages contain 6, 12, 24, and 16 units respectively, and each unit has 2 layers (composite layer with bottleneck layer). There is a single transition layer in between each dense block stage (for a total of 3 transition layers) which changes feature map size. Finally, there is 1 classification layer. 1 + 2(6) + 1 + 2(12) + 1 + 2(24) + 1 + 2(16) + 1 = 121. The base model we are using is DenseNet-121 BC with pre-trained weights from ImageNet. For feature extraction purposes, we load a network that doesn't include the classification layers at the top. The model utilizes transfer learning due to a training size of only 112,120 samples, compared to the millions of samples which modern day models use. The base layers of a model are very generic to the data set, while later layers get more specific and tailored to their data set. Originally a few extra layers were added on top of the DenseNet model to help learn specifics of thoracic diseases, but due to over-fitting, these layers were removed. Normally in transfer learning, only the top few layers are re-trained since they are specific to their base training data set, but we found better results by re-training the entire model end to end to learn the ChestXray14 data set. The machine learning pipeline consisted of these primary stages: \begin{enumerate} \item Use Google Cloud Storage bucket as primary data access point for the data set. This provided fast and scalable usage which allows any data set to easily be used. \item Pre-process and augment data set using Spark, downsampling, horizontal flipping, and mean/std normalization were some techniques utilized in this step. \item Initial model development was done in Google Colab, then ported over to Amazon SageMaker for a scalable and persistent platform to train the model. \end{enumerate} \section*{Metrics and Experimental Results} Accuracy, loss, and AUC scores are the main metrics used to evaluate the performance of the model. Training and validation loss curves were used to provide insight into the model performance. An initial loss curve may be seen in in Figure \ref{figloss}. It may be seen that the model started over-fitting near the second epoch, because of this the training was stopped at only 8 epochs since further training would lead to no benefits. Based on the loss curves, adding more layers and increasing complexity would most likely lead to more over-fitting. Further investigation into better data pre-processing may help alleviate over-fitting, such as further data augmentation to increase sample size, better handling of class imbalances, or using more thorough data sets such as CheXpert. For class imbalances specifically, some of the classes such as pneumonia had extreme imbalances, 1872 cases out of a total of 112,120 images; only 1.67\% of the overall data set. \begin{figure}[!htb] \centering \includegraphics[scale=0.6]{amia_template/pics/loss_curve.png} \caption{Model loss} \label{figloss} \end{figure} The overall AUC score of the model compared to previous attempts may be viewed in Table \ref{table:tableauc}. Multiple variations of the model with different pre-processing were tested. The 3 main variations which provided promising results were stochastic gradient descent with momentum with no horizontal flipping, stochastic gradient descent with momentum and horizontal flipping, and Adam optimizer with horizontal flipping. Other variations of flipping and model hyper parameter tuning were attempted but they did not provide sufficient results and are thus not included. Our variations of the model were able to get better performance in Atelectasis, Consolidation, Effusion, Fibrosis. Although these four diseases provided promising improvements, there were some large decreases AUC score compared to ChexNet. Infiltration, Nodule, and Pleural Thickening are three of the diseases whose AUC scores decreased substantially compared to CheXNet. Horizontal flipping actually decreased performance in most cases, we hypothesize this is due to applying this augmentation randomly across the entire data set, instead of focusing on specific classes, which may have exacerbated class imbalances which currently exist in the data set. \begin{table}[H] \begin{tabular}{p{3cm}|p{1.5cm}|p{1.5cm}|p{1.5cm}|p{1.5cm}|p{1.5cm}|p{1.5cm}|p{1.5cm}|p{1.5cm}} Pathology & Wang et al.\cite{ref7} & Yao et al.\cite{ref8} & Gündel et al.\cite{ref9} & Liu et al.\cite{ref6} & CheXNet\cite{ref5} & Ours (SGD w/o flipping) & Ours (Adam w/ flipping) & Ours (SGD w/ flipping) \\ \midrule Atelectasis & 0.716 & 0.772 & 0.767 & 0.781 & 0.8094 & \textbf{0.8104} & 0.7985 & 0.7799 \\ Cardiomegaly & 0.807 & 0.904 & 0.883 & 0.885 & 0.9248 & 0.8977 & \textbf{0.9055} & 0.8938 \\ Consolidation & 0.708 & 0.788 & 0.828 & 0.832 & 0.7901 & \textbf{0.7961} & 0.7945 & 0.7878 \\ Edema & 0.835 & 0.882 & 0.709 & 0.7 & 0.8878 & 0.8837 & \textbf{0.8849} & 0.8790 \\ Effusion & 0.784 & 0.859 & 0.821 & 0.815 & 0.8638 & \textbf{0.8798} & 0.8792 & 0.8658 \\ Emphysema & 0.815 & 0.829 & 0.758 & 0.765 & 0.9371 & \textbf{0.9143} & 0.8951 & 0.8334 \\ Fibrosis & 0.769 & 0.767 & 0.731 & 0.719 & 0.8047 & \textbf{0.8284} & 0.8063 & 0.7819 \\ Hernia & 0.767 & 0.914 & 0.846 & 0.866 & 0.9164 & \textbf{0.9097} & 0.8810 & 0.7738 \\ Infiltration & 0.609 & 0.695 & 0.745 & 0.743 & 0.7345 & \textbf{0.6999} & 0.6979 & 0.6854 \\ Mass & 0.706 & 0.792 & 0.835 & 0.842 & 0.8676 & \textbf{0.8214} & 0.8211 & 0.7837 \\ Nodule & 0.671 & 0.717 & 0.895 & 0.921 & 0.7802 & \textbf{0.7506} & 0.7226 & 0.7018 \\ Pleural Thickening & 0.708 & 0.765 & 0.818 & 0.835 & 0.8062 & \textbf{0.7713} & 0.7634 & 0.7505 \\ Pneumonia & 0.633 & 0.713 & 0.761 & 0.791 & 0.7680 & \textbf{0.7678} & 0.7498 & 0.7289 \\ Pneumothorax & 0.806 & 0.841 & 0.896 & 0.911 & 0.8887 & \textbf{0.8674} & 0.8533 & 0.8187 \\ \end{tabular} \caption{\label{table:tableauc}AUC Scores Comparison} \end{table} \section*{Discussion} The initial goal of this paper was to reproduce the competitive results from the ChexNet paper, and then improve upon the performance by using a more substantial data set. Due to increasing costs of training the model on Amazon Sagemaker, the decision was made to not use CheXpert as originally planned. Using only ChestXray14, better performance was achieved by using stochastic gradient descent (SGD) with momentum instead of the Adam optimizer. This was found to generalize better \cite{ref13} and provide better results on the test set. Other improvements to the performance would be utilizing deeper versions of the DenseNet model such as DenseNet-169, and DenseNet-201. Utilizing these models in an ensemble pattern would also provide benefits to the overall performance. Further plans to improve performance of the model were to integrate and train on the CheXpert dataset, this dataset has roughly twice the amount of images and also provides lateral chest X-rays, which have been found to account for 15\% accuracy in diagnosis of select thoracic diseases \cite{ref10}. The pre-processing Spark code was developed to be agnostic to datasets and easily provide the necessary pre-processing on the data set. Class Activation Maps (CAMs)\cite{ref11} were generated to visualize where the model was focusing to make its classification, an example may be seen in \ref{fig:cam_heatmap}. In the specific example generated by our model, the model correctly predicted Infiltration as the diagnosis and highlighted the right lung region which lead to the diagnosis. This is a useful tool for verifying correct and incorrect model predictions and help further fine-tune the model. \\ \begin{figure*}[!htb] \centering \begin{subfigure}[t]{0.5\textwidth} \centering \includegraphics[height=1.2in]{amia_template/infiltration_right_lung.png} \caption{Original Patient X-Ray} \end{subfigure}% ~ \begin{subfigure}[t]{0.5\textwidth} \centering \includegraphics[height=1.2in]{amia_template/infiltration_right_lung_cam.png} \caption{Infiltration of right lung highlighted} \end{subfigure} \caption{Patient X-Ray \& CAM Heatmap} \label{fig:cam_heatmap} \end{figure*} \section*{Conclusion} DenseNets provide state of the art thoracic disease detection at a fraction of the parameter cost of many modern day models. As a tool radiologists may use DenseNets to assist in initial diagnosis or verify patient diagnoses. ChestXray14 provides an excellent anonymoized dataset of chest X-rays which allows for the training of these high utility models. Using a DenseNet with data augmentation and hyperparameter tuning, we were able to surpass AUC and detection in select thoracic diseases. The use of class activation maps also enable verification of model focus and as a learning tool for radiologists to help identify what may lead to a diagnosis. Moving forward, CheXpert may be integrated as a larger data set and an ensemble model may be created using two convolutional towers, one for lateral photos and one for frontal photos. This combination of two separate orientations will help increase performance. Other variations of DenseNet may also be looked into such as the 169 and 201 layer versions of the model. The team is currently looking for funding to pursue such endeavours. As chest X-rays are the most significant examination tool used in practice for screening and diagnosis of thoracic disease, the team hopes to provide better tooling and support for such a vital component of patient support. With limited radiologists available, approximately two thirds of the global population have deficient access to a specialist for screening and diagnosis \cite{ref16}. Using this algorithm, patients without access to an expert may still be able to get expert level opinions and help reduce overall mortality rates throughout the world. \pagebreak \section*{Challenges} We encountered the following challenges in this project: \begin{enumerate} \item Cost of training on public cloud service like Amazon SageMaker, especially GPU. We learned to focus more on getting good results on public resources before porting over to a cloud instance for training. \item Format of Spark saving to and retrieving from HDFS, especially with png files. \item Transferring File format between pre-proccessing step and model training step \item Difficulties with getting the model to properly gain from transfer learning and the number of layers to unfreeze during training. Learned about varying depths of re-training layers and practices to ensure proper transfer learning such as normalization against the base data sets mean and std. \item Difficult to implement unit tests within deep learning code. There were some bugs which affected training output, but through careful analysis they were discovered. More research into unit testing frameworks has been pursued. \item Navigating a Dense121 Model to attach a hook to the correct layer. Needed to extract the correct neuron values and dimensions of the last convolution layer before flattening to generate the Class Activation Map (CAM). \end{enumerate} \section*{Contributions} We had full participation and collaboration from all group members. We met frequently on Google Hangouts to discuss strategies and progress, about a dozen meetings in all. We also collaborated via Slack (over 1000 messages). Filip Juristovski - modeling in Keras, model training/evaluation, prototype in Colaboratory, GitHub setup, Google Cloud Storage setup, paper Rushi Desai - modeling in PyTorch/SageMaker, Model training/evaluation and billing monitoring, paper Mohamed Abdelrazik - modeling in PyTorch/SageMaker, Class Activation Map (CAM), pre-processing in Spark, paper Doug Beatty - EMR prototype, SageMaker Keras prototype, LaTeX formatting, presentation slides, paper \makeatletter \let\oldsection\section \renewcommand\section{\clearpage\oldsection} \renewcommand{\@biblabel}[1]{\hfill #1.} \makeatother \bibliographystyle{unsrt} \begin{thebibliography}{1} \setlength\itemsep{-0.1em} \bibitem{ref1} Siamak N. Nabili, M. (2019). Chest X-Ray Normal, Abnormal Views, and Interpretation. [online] eMedicineHealth. \bibitem{ref2} CheXpert: A Large Dataset of Chest X-Rays and Competition for Automated Chest X-Ray Interpretation. [Internet]. Stanfordmlgroup.github.io. 2019. \bibitem{ref3} FAN M, XU S. Massive medical image retrieval system based on Hadoop. Journal of Computer Applications. 2013;33(12):3345-3349. \bibitem{ref4} Huang G, Liu Z, van der Maaten L, Weinberger K. Densely Connected Convolutional Networks [Internet]. arXiv.org. 2019. \bibitem{ref5} Rajpurkar P, Irvin J, Zhu K, Yang B, Mehta H, Duan T et al. CheXNet: Radiologist-Level Pneumonia Detection on Chest X-Rays with Deep Learning [Internet]. arXiv.org. 2019. \bibitem{ref6} Liu H, Wang L, Nan Y, Jin F, Pu J. SDFN: Segmentation-based Deep Fusion Network for Thoracic Disease Classification in Chest X-ray Images [Internet]. arXiv.org. 2019. \bibitem{ref7} Wang X, Peng Y, Lu L, Lu Z, Bagheri M, Summers R. ChestX-Ray8: Hospital-Scale Chest X-Ray Database and Benchmarks on Weakly-Supervised Classification and Localization of Common Thorax Diseases. 2019. \bibitem{ref8} Yao L. Weakly supervised medical diagnosis and localization from multiple resolutions [Internet]. Arxiv.org. 2019. \bibitem{ref9} Guendel S, Grbic S, Georgescu B, Zhou K, Ritschl L, Meier A et al. Learning to recognize Abnormalities in Chest X-Rays with Location-Aware Dense Networks [Internet]. arXiv.org. 2019. \bibitem{ref10} Raoof S, Feigin D, Sung A, Raoof S, Irugulpati L, Rosenow E. Interpretation of Plain Chest Roentgenogram. 2019. \bibitem{ref11} Zhou B, Khosla A, Lapedriza A, Oliva A, Torralba A. Learning deep features for discriminative localization [Internet]. Arxiv.org. 2019. \bibitem{ref13} Wilson A, Roelofs R, Stern M, Srebro N, Recht B. The Marginal Value of Adaptive Gradient Methods in Machine Learning [Internet]. Arxiv.org. 2017. \bibitem{ref16} Mollura, Daniel J, Azene, Ezana M, Starikovsky, Anna, Thelwell, Aduke, Iosifescu, Sarah, Kimble, Cary, Polin, Ann, Garra, Brian S, DeStigter, Kristen K, Short, Brad, et al. White paper report of the rad-aid conference on international radiology for developing countries: identifying challenges, opportunities, and strategies for imaging services in the developing world. Journal of the American College of Radiology, 7(7):495–500, 2010 \end{thebibliography} \end{document} The base model is DenseNet-121 using pretrained weights from ImageNet. We load a network that doesn't include the classification layers at the top; this is ideal for feature extraction. We make the model non-trainable since we will only use it for feature extraction; we won't update the weights of the pretrained model during training. We will concatenate DensNet and add more layers on top of that. We freeze the original layers and only train additional layers. ReLu activation Add a dropout rate of 0.2 Add a final sigmoid layer for classification. Issues while training: Dealing with class imbalance was one of the main issues we faced. We plan to use data augmentation methods like flipping on horizontal and vertical axes etc. We also used a phased approach to training where we kept most of the layers frozen while initial training and subsequently unfroze more and more layers. This helped in debugging and having a sanity check. @rushi: DesneNet takes the idea of ResNet and takes it further. We take connections from all previous layers and connect it to current layer. The bypass connection because it precisely means that we are concatenating (concatenate means add dimension, but not add values!) new information to the previous volume, which is being reused.
\subsection{L'H\^{o}pital / l'Hospital} \begin{frame}{Limits with L'H\^{o}pital} \begin{itemize} \item \textbf{Intuitive:}\\ \begin{displaymath} \lim\limits_{n \rightarrow \infty} 2 + \dfrac{1}{n} = 2 + \dfrac{1}{\infty} = 2 \end{displaymath} \vspace{0em}\\ \item<2- |handout:1> \textbf{With L'H\^{o}pital:} \begin{itemize} \item Let $f, \, g : \mathbb{N} \rightarrow \mathbb{R}$ \item If \begin{math} \lim\limits_{n \to \infty} f(n) = \lim\limits_{n \to \infty} g(n) = \infty / 0 \end{math} \end{itemize} \begin{displaymath} \Rightarrow \lim\limits_{n \rightarrow \infty} \dfrac{f(n)}{g(n)} = \lim\limits_{n \rightarrow \infty} \dfrac{f'(n)}{g'(n)} \end{displaymath} \item<3- |handout:1> \textbf{Holy inspiration} \begin{center} you need a doctoral degree for that \end{center} \end{itemize} \end{frame} %------------------------------------------------------------------------------- \begin{frame}{Limits with L'H\^{o}pital} \textbf{The limit can not be determined in the way of an Engineer:} \begin{displaymath} \lim_{n \to \infty} \dfrac{\ln (n)}{n} = \dfrac{\lim_{n \to \infty}\; \ln (n)}{\lim\limits_{n \to \infty}\; n} \hspace{1em} \stackrel{\text{plugging in}}{\longrightarrow} \hspace{1em} \dfrac{\infty}{\infty} \end{displaymath} \textbf{Determine the limit using L'H\^{o}pital:} \begin{displaymath} \lim\limits_{n \rightarrow \infty} \dfrac{f(n)}{g(n)} = \lim\limits_{n \rightarrow \infty} \dfrac{f'(n)}{g'(n)} \end{displaymath} \end{frame} %------------------------------------------------------------------------------- \begin{frame}{Limits with L'H\^{o}pital} \begin{block}{\textbf{Using L'H\^{o}pital:}} Numerator: \; $\textit{\textbf{f(n)}}\!: n \mapsto \ln (n)$\\ Denominator: $\textit{\textbf{g(n)}}\!: n \mapsto n$\\ \hspace{1.5em} $\Rightarrow f'(n) = \dfrac{1}{n}$ \; (derivation from Numerator)\\ \hspace{1.5em} $\Rightarrow g'(n) = 1$\; (derivation from Denominator)\\ \begin{displaymath} \lim\limits_{n \rightarrow \infty} \dfrac{f'(n)}{g'(n)} = \lim\limits_{n \rightarrow \infty} \dfrac{1}{n} = 0 \hspace{0.5em} \Rightarrow \hspace{0.5em} \lim\limits_{n \rightarrow \infty} \dfrac{f(n)}{g(n)} = \lim\limits_{n \rightarrow \infty} \dfrac{\ln (n)}{n} = 0 \end{displaymath} \end{block} \end{frame} %------------------------------------------------------------------------------- \begin{frame}{Limits with L'H\^{o}pital} \textbf{What can we take for granted without proofing?} \begin{itemize} \item Only things that are trivial \item It is always better to proof it \end{itemize} \textbf{Examples:} \begin{eqnarray*} \lim\limits_{n \rightarrow \infty} \dfrac{1}{n} &= \; 0 &\hspace{2em} \text{is trivial}\\ \lim\limits_{n \rightarrow \infty} \dfrac{1}{n^2} &= \; 0 &\hspace{2em} \text{is trivial}\\ \lim\limits_{n \rightarrow \infty} \dfrac{\log (n)}{n} &= \; 0 &\hspace{2em} \text{use L'Hopital} \end{eqnarray*} \end{frame}
\chapter{Introduction} \section{Background}\label{sec:background} \input{introduction/background.tex} \section{Literature Review}\label{sec:literature-review} \input{introduction/literature-review.tex} \section{Objectives and Methodology}\label{sec:objectives-and-methodology} \input{introduction/objectives-and-methodology.tex}
\section{Introduction} IPv6 over Low-power Wireless Personal Area Networks (6LoWPAN\footnote{We use the acronym 6LoWPAN to refer to Low power Wireless Personal Area Networks that use IPv6}) is a working group inspired by the idea that even the smallest low-power devices should be able to run the Internet Protocol to become part of the Internet of Things. The main function of a low-power wireless network is usually some sort of data collection. Applications based on data collection are plentiful, examples include environment monitoring~\cite{Tolle:2005}, field surveillance~\cite{Vicaire:2009}, and scientific observation~\cite{Werner-Allen:2006}. In order to perform data collection, a cycle-free graph structure is typically maintained and a convergecast is implemented on this network topology. Many operating systems for sensor nodes (e.g. Tiny OS~\cite{Levis2005} and Contiki OS~\cite{Dunkels:2004}) implement mechanisms (e.g. Collection Tree Protocol (CTP)~\cite{Fonseca:2009} or the IPv6 Routing Protocol for Low-Power and Lossy Networks (RPL)~\cite{rfc6550}) to maintain cycle-free network topologies to support data-collection applications. In some situations, however, data flow in the opposite direction --- from the root, or the border router, towards the leaves becomes necessary. These situations might arise in network configuration routines, specific data queries, or applications that require reliable data transmissions with acknowledgments. Standard routing protocols for low-power wireless networks, such as CTP (Collection Tree Protocol~\cite{Fonseca:2009}) and RPL (IPv6 Routing Protocol for Low-Power and Lossy Networks~\cite{rfc6550}), have two distinctive characteristics: communication devices use unstructured IPv6 addresses that do not reflect the topology of the network (typically derived from their MAC addresses), and routing lacks support for any-to-any communication since it is based on distributed collection tree structures focused on bottom-up data flows (from the leaves to the root). The specification of RPL defines two modes of operation for top-down data flows: the non-storing mode, which uses source routing, and the storing mode, in which each node maintains a routing table for all possible destinations. This requires $O(n)$ space (where $n$ is the total number of nodes), which is unfeasible for memory-constrained devices. Our experiments show that in random topologies with one hundred nodes, with no link or node failures, RPL succeeds to deliver less than 20\% of top-down messages sent by the root (see Figure~\ref{fig:txdwn}). Some works have addressed this problem from different perspectives~\cite{Rein12, Duque13, xctp}. CBFR~\cite{Rein12} is a routing scheme that builds upon collection protocols to enable point-to-point communication. Each node in the collection tree stores the addresses of its direct and indirect child nodes using Bloom filters to save memory space. ORPL~\cite{Duque13} also uses bloom filters and brings opportunistic routing to RPL to decrease control traffic overload. Both protocols suffer from false positives problem, which arises from the use of Bloom filters. \textcolor{blue}{Even though CTP does not support any-to-any traffic, XCTP \cite{xctp}, an extension of this protocol, uses opportunistic and reverse-path routing to enable bi-directional communication in CTP. XCTP is efficient in terms of message overload, but exhibits the problem of high memory footprint.} In this work, we build upon the idea of using hierarchical IPv6 address allocation that explores cycle-free network structures and propose Matrix, a routing scheme for dynamic network topologies and fault-tolerant any-to-any data flows in 6LoWPAN. Matrix assumes that there is an underlying collection tree topology (provided by CTP or RPL, for instance), in which nodes have static locations, i.e., are not mobile, and links are dynamic, i.e., nodes might choose different parents according to link quality dynamics. Therefore, Matrix is an overlay protocol that allows any low-power wireless routing protocol to become part of the Internet of Things. Matrix uses only one-hop information in the routing tables, which makes the protocol scalable to extensive networks. In addition, Matrix implements a local broadcast mechanism to forward messages to the right subtree when node or link failures occur. Local broadcast is activated by a node when it fails to forward a message to the next hop (subtree) in the address hierarchy. \textcolor{blue}{After the network has been initialized and all nodes have received an IPv6 address range, three simultaneous distributed trees are maintained by all nodes: the collection tree (Ctree), the IPv6 address tree (IPtree), and the reverse collection tree (RCtree). The Ctree is built and maintained by a collection protocol (in our case, CTP). It is a minimum cost tree to nodes that advertise themselves as tree roots. The IPtree is built by Matrix over the first stable version of the Ctree in the reverse direction, i.e., nodes in the Ctree receive an hierarchical IPv6 address from root to leaves, originating a static structure. Since the Ctree is dynamic, i.e., links might change due to link qualities, at some point in the execution the IPtree no longer corresponds to the reverse Ctree. Therefore, the RCtree is created to reflect the dynamics of the collection tree in the reverse direction.} Initially, any-to-any packet forwarding is performed using Ctree for bottom-up, and IPtree for top-down data flows. Whenever a node or link fails or Ctree changes, the new link is added in the reverse direction into RCtree, and it remains as long as this topology change persists. Top-down data packets are then forwarded from IPtree to RCtree via a local broadcast. Whenever a node receives a local-broadcast message, it checks whether it knows the subtree of the destination IPv6 address: if yes then the node forwards the packet to the right subtree via RCtree and the packet continues its path in the IPtree until the final destination. We evaluated the proposed protocol both analytically and by simulation. Even though Matrix is platform-independent, we implemented it as a subroutine of CTP on TinyOS and conducted simulations on TOSSIM. Matrix's memory footprint at each node is $O(k)$, where $k$ is the number of children at any given moment in time, in contrast to $O(n)$ of RPL, where $n$ is the size of the subtree rooted at each routing node. Furthermore, we show that the probability of a message to be forwarded to the destination node is high, even if a link or node fails, as long as there is a valid path, due to the geometric properties of wireless networks. Simulation results show that, when it comes to any-to-any communication, Matrix presents significant gains in terms of reliability (high any-to-any message delivery) and scalability (presenting a constant, as opposed to linear, memory complexity at each node) at a moderate cost of additional control messages, when compared to other state-of-the-art protocols, such as XCTP and RPL. \textcolor{blue}{In addition, when compared to our any-to-any routing scheme, the reverse-path routing is more efficient in terms of control traffic. However, the performance of XCTP is highly dependent on the number of data flows, and can be highly degraded when the application requires more flows or the top-down messages are delayed.} To sum up, Matrix achieves the following essential goals that motivated our work: \begin{itemize} \item \textbf{Any-to-any routing}: Matrix enables end-to-end connectivity between hosts located within or outside the 6LoWPAN. \item \textbf{Memory efficiency}: Matrix uses compact routing tables and, therefore, is scalable to extensive networks and does not depend on the number of flows in the network. \item \textbf{Reliability}: Matrix achieves $99\%$ delivery without end-to-end mechanisms, and delivers $\geq 90\%$ of end-to-end packets when a route exists under challenging network conditions. \item \textbf{Communication efficiency}: Matrix uses adaptive beaconing based on Trickle algorithm \cite{Levis:2004} to minimize the number of control messages in dynamic network topologies (except with node mobility). \item \textbf{Hardware independence}: Matrix does not rely on specific radio chip features, and only assumes an underlying collection tree structure. \item \textbf{IoT integration}: Matrix allocates global (and structured) IPv6 addresses to all nodes, which allow nodes to act as destinations integrated into the Internet, contributing to the realization of the Internet of Things. \end{itemize} The rest of this paper is organized as follows. In Section~\ref{sec:matrix}, we describe the Matrix protocol design. In Section~\ref{sec:analysis}, we analyze the message complexity of the protocol. In Section~\ref{sec:results}, we present our analytic and simulation results. In Section~\ref{sec:related}, we discuss some related work. Finally, in Section~\ref{sec:conclusion}, we present the concluding remarks.
\documentclass[11pt]{article} \usepackage{listings} \begin{document} \noindent \section*{L3 notes} \subsection*{Some terms} d(h * f) h convolve with f \\ Know what the math equations are doing and apply them\\ %There is no blue cell after green cell Pad the sides with 0 and shift the kernel across the numbers\\ floor(kernel size / 2)\\\\ $[1,1,1 ]$ symmetric\\ Linear (shift invariant) = output Is scaled accordingly\\ \\ \ Correlation filter to shift pixels in image \\\\ Normalised = summed up add to 1\\ Effects are negligible for large images\\\\ Gaussian kernel depends more on the sigma\\\\ Salt and pepper = isolated pixels that are problematic\\ Smooth away the impulse and spread it all around\\ Impulse is salt without the pepper\\\\ Higher signal amplify both the signals and noise \\\\ Histogram stretching adjust contrast\\\\ \ Bitmap save the pixels independently\\ \subsection*{Laplacian} the process to get the residual is [upsample (fill with 0s) $\rightarrow$ blur $\rightarrow$ subtract from original]\\ (the reason for the blur is to "spread out" the values over the filled-in black pixels) \newpage \noindent Q: Does spatial quantization mean the quantisation of values of x and y? i.e. x and y can only take discrete integer values?\\ A: spatial quantization basically happens because we cant represent continuous x and y coordinates in a discrete system\\ \\ Q: It seems that you always regard intensity as integers, is it a routine for this course?\\ A: Yes and no\\ \\ Q: does adjusting abstract and brightness simply refer to the linear mapping or also include the non-linear gamma mapping\\ A: Non-linear mapping also just the contrast\\ Photography operation we don’t use stretching ( we use images that stretch over the entire range) \\\\ Q: In practice, is convolution used more than correlation?\\ A: Convolution\\ \\ Q: Is reconstructing the original image using laplacian pyramid 100\% lossless?\\ A: Up to the difference of quantisation \\\\ Q: Can we compensate motion blur by finding the motion blur kernel and use the inverse kernel to demotion blur?\\ A: Yes, finding the kernel is always hard \\\\ Q: Is convolution invertible? In a sense that let's say we have a “convolved” image, is there always a filter such that we can recover the original image using convolution? e,g, undoing blur convolution using a specific sharpening convolution\\ A: If we throw away half of the pixels \\\\ Q: Does laplacian pyramids take 2* space than gaussian pyramids simply because laplacian pyramids have 2 sets of the pyramids (gaussian + residual)?\\ A: Same amount of space \\\\ %Low pass filtering signal into low domain frequency %High frequency represent sharp edges %Slow changing parts to remain and we take care of the fast changing pixels %We can take it as a blurring filter %2k + 1 is the size of the kernel \section*{L4 notes} \subsection*{Some terms} mean filter does not remove all noise and blurs the image only isolated values 0-255 \\\\ median filter remove all noise and blurs the image slightly arrange in increasing starting from 0 \\\\ difference filter sum up all the values in row same value for the entire row \\\\ each pixel has a tangent plane \\\\ kernel size controls the strength of the filter \\\\ border problem output is reduced in size for the pixels along the edge \\\\ the image patch and the template always contain positive numbers, cos $\Theta \in [0, 1]$, i.e., the output of normalized cross-correlation is normalized to the interval [0,1], where 0 means no similarity and 1 means a complete similarity. \\\\ region of interest can benefit template matching \\\\ image has discrete representation we need approximation, positive gradient value when the image change from dark to bright and negative when reversed image \\\\ Image sharpening g(x,y)=f(x,y)- f(x,y) $\circ $ h(x,y) \\\\ Magnitude = $\sqrt{(gx2 + gy2 )}$\\\\ Approximated magnitude = $|$gx $|$ + $|$gy $| $ \\ non maxim suppression if edge has a magnitude too small connected to another pixel above a threshold, don’t prune \\\\ extract edges to detect start and end edges , useful for 3d to know the shape and geometry\\ why? resilient and lighting and color useful for recognition \\ \\ \subsection*{Template matching } This object is now the template (kernel) and by correlating an image with this template, the output image indicates where the object is. Each pixel in the output image now holds a value, which states the similarity between the template and an image patch (with the same size as the template) centered at this particular pixel position. The brighter a value, the higher the similarity. \\\\ Purely correlation since strongest response is when original image exactly matches output\\ what happens when u zoom the baby's face 2x (refer to image)? \\\\ Template is not symmetrical \\ \subsection*{Neighborhood processing }\\ Neighbor pixels play a role when determining the output value of a pixel \\ \subsection*{Convolution vs Correlation }\\ Convolution (rotated 180 degrees)\\ h(i, j ) $\cdot$ f (x - i, y - j ) \\\\ Correlation’\\ h(i, j ) $\cdot$ f (x + i, y + j ) \\\\ To check if same result, the kernel before and after 180 degrees are same \\\\ Intuition of Sobel filter\\ gx (x, y) ≈ f (x + 1, y) − f (x - 1, y) \\ correlate [−1, 0, 1] with the image\\ $[-1,0 ,1]$\\ $[-2 ,0 ,2]$ = $2[-1, 0 ,1]$ (put more weights at center)\\ $[-1 ,0, -1]$\\ \\ Combine the both result using the horizontal and vertical Sorbel to get the final edge image \\ 3x3 kernel is used as we need to include the neighbours as single row or single column kernel is sensitive to noise \\ \\ \\ \subsection*{Derivatives}\\ does not matter the order of the derivative and gaussian blur\\ gaussian filter to remove noise before laplacian applied\\ \\\\ vertical shows pixel of image row\\ horizontal shows the gradient value \\ \\ f(x) grey level value\\ f'(x) gradient value\\ $[1,-2,1]$\\ f''(x) gradient of the gradient \\ \\\\ gxx (x, y) $\approx$  f (x - 1, y) − 2 \cdot f (x, y) + f (x + 1, y)\\ gyy (x, y) $\approx$  f (x, y - 1) − 2 \cdot f (x, y) + f (x, y + 1) \\ \subsection*{First order derivative}\\ Sobel is a combination of derivative kernel\\ Sobel results in wide edges as it is first order\\ First order derivative (thicker edges)\\ Roberts, Prewitt, Sobel filter \\ \subsection*{Second order derivative}\\ Second order derivative can know the exact edge and detect 1 px thin edge Smoothing is needed\\ DoG (difference in gaussian)\\ laplacian is the second order derivative (most sensitive to noise)\\ -1 white 0 grey 1 black \\ \\ To approximate the 2nd order derivatives\\ gxx (x, y)  $\approx$ f (x − 1, y) − 2 · f (x, y) + f (x + 1, y) represents [1;-2;1] \\ gyy (x, y)  $\approx$ f (x, y − 1) − 2 · f (x, y) + f (x, y + 1) represents [1 -2 1] \\\\ \\\\ \subsection*{Hysterisis}\\ pixels below some value 0\\ hysterisis join the strong and weak pixels\\ thresholding depends on the image\\ \\ cv2.canny is interpolated version \\ random forest is a learned model from human markups\\ \\gradient shift dark to light and light to dark \\\\ is the center a local maximum or not if yes keep it as part of the edge else discard it \\ %don’t know how far this analogy is going to uphold \\\\ \ \\\\ Q: would there be multiple local maxes after performing the non-maximum suppression?\\ A: no multiple local maxes, strong response right next to each other \\\\ Q: is horizontal gradient detection always from left to right? similar for vertical case.\\ A: left to right\\ \\ Q: Could you explain the intuition behind why cross correlation isn't commutative/associative, even tho convolution is just flipping the kernel? \\ A: [1, 2, 3] cross correlation [3, 2, 1] is not the same as [3, 2, 1] cross correlation [1, 2, 3] \\\\ $[1, 2, 3]$ cross convolution [0, 1, 0] is [3, 2, 1] so it is not identity \\ \\\\\\ Q: From slide 9, how is the 1D derivative filter constructed from the finite differences discrete version equation with h = 2?\\ A: 2 elements we are using \\\\ Q: When convolution/cross-correlation is mentioned, is full padding assumed by default?\\ A: is not full padding, lecture examples are only full padding \\\\ \noindent Q: is padding to just inserting zero rows and zero columns or that plus blurring/interpolation? It seems to have been used both ways having to do nn interpolation (bilinear, linearly solve between 2 neighbours)0 interspersed in rows and columns \\ %blue line falls can estimate what the ratio is then multiply by pi blurring to reduce noise (to avoid enhancing the noise) \\\\ Q: I think it was mentioned last lecture that convolutions are generally invertible. How do we reconcile this with the notion that blurring is lossy?\\ A: convolution is multiplicity in the inverse domain (do division can have problems)\\\\ blurring in itself is not lossy only downsampling \\ for every single elements, composed on several pixels, mixture of weights, same kernel applied to next kernel blurring + downsampling makes it lossy \\\\ factor all of this in the system of equations should be able to recover the image \\\\ Q: why not take the residual of the original versus upsampled of previous image\\ A: remove some values these are the values we want to preserve in the residual else will keep some of the detailing \\ \section*{L6 notes} \subsection*{Some terms} bandwidth is too narrow not very representative \\ we don't know what is the correct/ incorrect value for bandwidth \\ sum of all the gaussian forms the new curve \\ dirac delta - bandwidth is very small \\ number of textons can be smaller/larger than the filter banks \\ euclidean distance between histogram ends up compensating for each other \\ What are textures used for?\\ cue to tell us on the underlying 3d structure \\ scale of the envelope, single or many wavelengths\\ \\ running across all the images where each image is a pixel \\run the cluster where every single pixel and image is a datapoint replace all pixels in the email with the texton id, compute the histogram based on the samples, each of the texton image is represented with a histogram \\ texton id is per pixel \\ x and y then the texton would not be purely texture \\\\ texture is independent feature to the segment it belongs to, we don't have to do segmentation to find the segment in the first place \\ the responses is for the whole filter bank \\ Do k-means twice\\ first k means to form texton dictionary\\ second k means NN search (can also apply mean-shift)\\ \\ \\histogram is 100 dimension vector also \\ Feature Representation\\ Filter bank Response\\ Texton histogram\\ \\ Note: Texton histogram as a feature for segmentation will not give a clear segmentation, problematic edges, results in a pixelated image for the texture (not localised)\\ Good localization, pixel from the 1 pixel or all over is the same \\ CNN is aggregation of many filters, take a feature response and apply another kernel to it \\ blurring each channel independently (2d blurring), now we are blurring the filter response \\ we have consider the location of the pixel for segmentation \\ region is bounded by two separate histograms, then u would have separate results \\ Q: Are we able to somehow use a filter to extract coloraturas as a filter inside the filter bank? So that we can run clustering algo on both texture and colour at the same time?\\ A: you can mix the colors if you want, create a gabor filter for each channel\\ \\ Q: can I clarify whether textons are generated based on clustering done over all filter results within a filterbank? Or is it done using only some sort of 'most differentiating' filter result?\\ A: filter bank only to apply to all images \\ apply 2d convolution \\ Q: how does using the same filter bank ensure the bins are the same\\ A: having very different feature response\\ 1 image per type then maybe \\ Q: Why 3 clusters?\\ A: there is nothing to distinguish the skin from the background \\ \subsection*{Quiz 1} Red and green considered equally, but blue is not considered at all\\ Maximum shades of grey will not be the shade \\ \section*{L7 notes} \subsection*{Some terms} SSD\\ keypoints are also corners or interest points\\ low error will look dark, high error will look bright\\ shape is going to affect the ellipse, size does not matters \\ H = [0 0 ; 0 C] gradient is x direction is 0\\ H = [A 0 ; 0 0] gradient is y direction is 0\\ \\ greedy approach non-maximum suppression has keypoints approximately in the same location as it looks for areas that has high contrast \\ automatic scale selection, harris is equivariant to changes of scale\\ \subsection*{Weights of derivative} gaussian before we do the summation for the weights, more weight at the center, less weights at the edge \\ \\ Instead of applying the effects, we are looking at two viewpoints under two different lighting conditions \\\\ highest response has a signal has characteristic scale that has the same as gaussian, width of signal corresponds in signal charasteristic \\\\ Harris operator is more efficient compared to eigen value decomposition\\ If the region is unusual then it is difficult for matching, approximated distinctiveness with SSD error \\ Linearize with 2nd moment matrix\\ Quantify distinctiveness with eigenvalues of H \\ R is the cornerness is defined as \\ R = det(H) - k $trace^{2}$(H) \\\\ Values can be obtained from the matrix itself \\\\ LoG finds blobs (keypoint detector that tries to find roughly circular regions) maximum scale is already built-in (maximum size of the kernel wrt to image) \\\\ Auto correlation: Create a template of the patch, shift it around where I use the local patch \\ Q: Is template the benchmark for comparison? A: strongest peak where it matches to itself Refer to template matching\\ \\ No matter where u shift the template, will get a strong response at the sky\\ Third dimension is the intensity \\ We need 3d… How do we analyse the points without looking at 3d\\ \\ $\lambda_{min}$ and $\lambda_{max}$ are perpendicular to each other\\ \\ SSD error E(u, v)\\ Error will be 0 or greater\\ H is always positive definite\\ Semi definite where there is 0 case, flat region only in synthetic images \\ Cross section is approximately circular ( a lot of change in all directions)\\ Direction of the fastest change perpendicular to the slowest change will be approximately equal\\ Which direction I change in it is going to be different \\ Contrast causes the threshold\\ $\lambda_{min}$ would be small as $({\lambda_{min}})^{-\frac{1}{2}}$ where there is no change on the straight line \\ \\ \\ Q: Clustering the responses of the textons\\ A: The response are the data points, each feature response is 1 dimension, each data point cluster in 38 dimensions \\ Dimensionality: Refer to L6 supplements\\ One blue dot is 1 pixel, x location is 1 feature value and y location is 1 feature value \\ Eigenvalue decomposition of pixel then u would get every pixel also\\ axis length is very long \\\\ Q: Texture and template matching are they the same?\\ A: Correlate the long, what is the pattern vs the individual image. Detecting many texture in 1 image, so the feature response will be different in different part of images. Only a particular filter is tuned to that signature response. Normally we don't have to hand-create the filters. Deep learning to learn whole bunch of features, or gabor filter, can tune the filters. Over many dimensions can get a unique response to that example. \\\\ Q: Filter bank to find the size\\ A: Large enough filter bank or some way to count \\\\ Binary classification if the sheet is defect or not \\\\ Q: Why is the skin and background cannot be segmented?\\ A: Texture of the background is very large, approximate scale of the marble is on par with the arm. Doing agnostic segmentation, we don't model the content in the image, only based on filter response. There is no reason why it should end up in certain segmentations. \\ Clustering is done over all of the pixels over all of the images. Creating the local histogram is trial and error \section*{L8 notes} \subsection*{Some terms} Descriptors are parameter independent\\ SIFT - scaling iterative feature response\\ Pixel wise difference (gradients) - more sensitive to relative location but sensitive to deformations \\ Color histogram - 3d histogram \\ What size of the cells do we want, fine grids, overlap etc Bin sizes - more finely tuned, a small shift will affect the histogram \\ Compare histogram - chi square \\ Orientation normalization\\ \subsection*{Averaging}\\ Bimodal distribution average end up with dominant orientation with no gradient\\\\ MOPS or GIST is no longer used as a descriptor\\ \\\\ \subsection*{Mode - SIFT}\\ SIFT - understand the implication of doing this\\ Can be combined with other keypoint detector \\ as the threshold is larger, it removes more keypoints, depends on illumination difference\\ \\ poorly localised if it sits on an edge and not a corner\\ corners have high curvature, edges have low curvature\\ \\ needs to be clear where the keypoint is matched to when moving in a straight line\\ \\ ratio of eigenvalues to be below the edge thresh high threshold more tolerant of edges\\ smaller bar to be corner, longer bar is edge\\ white on black and black on white difference\\ black bar cannot be keypoints as we also have the surrounding neighbors\\ \\ We don't assign gradients in original orientation - dominant orientation \\ Taking the original histogram with some wrapping operation, form of normalisation wrt dominant orientation\\ Normalize to unit length\\ If it exceeds the threshold set the threshold value, rectify and assign it. Then renormalize.\\ Clamping is to encourage invariance to small changes to illumination, over count in certain orientations. \\ can use in the dense form where it can use in any rotation \\ High robust \\ \\ \subsection*{Feature matching} \subsection*{Image transformation} Filtering\\ Only changes on the actual image intensities\\ G(x) = h \{ F(x)\ \} Warping\\ G(x) = F \{ h(x)\ \} changes the location of the pixels \\\\ \section*{L9 notes} \textbf{2d projective transformation}\\ affine: parallel lines are still preserved projective: also known as a homography, try to solve for the parameters for a projective transformation\\ Not an arbitrary matrix with 9 degrees of freedom (3x3)\\ Solve for H using direct linear transform \\ Apply homography to align two images together \subsection*{SVD} $A = U \sum V^{T}$\\ A - 8 $\times$ 9\\ U - 8 $\times$ 9\\ $\sigma$ - 9 $\times$ 9\\ V - 9 $\times$ 9\\ \\ V is a singular matrix\\\\ singular values found on diagonal values of sigma\\ columns of V are single vectors \\ N number of correspondences \\ Normalization such that the centroid is (0, 0) of the similarity transformation is a whitening step \\ RANSAC deal with outliers, sample from the set of noisy observations \\ Even though we can sample more, we usually s to be equal to the number of the outliers \section*{L10 notes} Hessian is the 2nd order derivative\\ \subsection*{Optical flow} The bigger the arrow, the stronger the flow \\ Small motion assumption - Linear wrt to the location \\\\ Constant flow\\ All flow in the same region will have a flow \\ Ax = b A is not a square matrix \\\\ Have different motions to avoid aperture problem\\ motion is not small, we end up with wrong matches and estimate shift are actually not smaller than the actuals shift \\ $\rightarrow$ reduce the resolution \\ \\ smoothing the flow vectors are \\ warp and upsample, compute the flow until we reach the highest resolution \\ Line and smooth location, we cannot take the inverse, can only get sparse motion flow with Lucas kanade \\ Until we get the closest match\\ Mode represent location in the image space, feature representation most closest to the template\\\\ Issues with computing flows at object edges\\ \\ How to associate from 1 frame to another frame\\\\ With optimal flow, we can see if people are moving in or out \\ sum of x is the projective range of the template, only for the template not warping the whole image to find the template\\ \\ When p = 0, there is no translation, so there is only the change of intensity over time\\\\ Do warp on observation, make the comparison between the warped observation and increment on top of it \\ Template should stay the same from start to finish, depending on the direction of the warp\\\\ $I_{t}$ if p = 0 as we are updating the whole image after every step, warp image on template\\\\ $T(x) - I(W(x;p))$ \\Warping from template to observation image or vice versa \\ Number of pixels in the blob would give an indication of how many people are together \\\\ \\Suitable for large images \\\\ \textbf{Horn Schunck}\\ Assumption: smooth flow field\\ Is lambda is small that the flow goes to 0, then it gives a degenerate flow\\ Then we have the smoothest possible flow, i.e. a constant flow field.\\ We can also pick lambda to be extremely large, in which case there will be no smoothing at all. \\ As a min problem, u and v to be small \\ \\ Each pixel flow can be different \\ Difference in flow between adjacent pixels are small \\ uniformly flow field will have the lowest flow field compared to the random flow field \\ We also consider the right and top neighbour so we won't have to double count everything \\ $u_{i, j}$ appears 4 times as it is being referenced by the neighbours \\ Only suitable when in the video frames movements are small \\ Does not mean that there is motion in the underlying object\\ For every model, go back and question our assumptions\\ \\\\ Motions are large how to solve this?\\ Coarse to fine estimation using LK \\ Or non linear assumptions like Horn Schuncks \\ \section*{L11 notes} \subsection*{Tracking} Tracking the speed of the action\\ Estimate volume of heart chamber\\ We can't rely only on optimal flow for tracking\\ \\ First search at coarser scale\\ Only need to search on local region based on previous state \\ Based on initial location so it has to be good \\ Can have other types of transformation, rather than just homography (projective transform) \\ no closed form to express I as it has no parameters for p \\ Can only compare as much pixels as in the template \\ Do in a matrix instead of a loop form, each element is independent so we can parallelise \\\\ \textbf{KLT algorithm}\\ Refresh population of possible corners as features of tracking\\\\ \textbf{Duality of feature tracking vs Optimal flow}\\ Feature tracking\\ Follow specific pixels As we solve optical flow problem then we can track features, vice versa\\ \subsection*{Mean shift} Depends on the background\\ Spatial layout - what is in the template layout\\ Not allowing the template to change in size then it will change the distribution of the color histogram, much less than in original template, has issues with scaling (additional dimension in scale) \\ How do we bin the colors?\\ 10 bins per color channel, then we have 30, 3d histogram that is compounded for every channel. \\ 10 bins may not be discriminative enough to distinguish two shades of color\\ \\ Initialize for a specific data point and apply to every point\\ Every point that end up at the same attraction basin belongs to same centroid\\ Move the points to the centroid to calculate the mean shift vector for every single point\\ Location that we end up at are the local maxima called attraction basin\\\\ The reason we do for every single point for segmentation is we want to identify the membership for each mode \\ \\ b is the binning function\\ Look at m which bin does it go into, if it go to mf bin, then $b(x_{n} - m) $= 0 and delta function goes to 1\\ Contribution to q is 0, does not contribute to descriptor value\\ We are trying to pick out the points that have the colors\\ Normalizing with the size of the target\\ \\ We use Bhattacharyya co-efficient as similarity measure (compare histograms) chosen as our feature, if we were using distance measure choose L2\\\\ Bhattacharyya co-efficient, L2 is not very ideal for mean-shift\\ Find the peak of mode or maximizing over all the possible locations y \\ Assign to new target and calculate the candidate again\\\\ \textbf{Challenges of mean shift}\\ We assume the bounding box is going to move the same but if the person is moving the hand further from the camera, so it is not a good assumption \\\\ Repeating the procedure from frame to frame, we may suffer issue from drift (cannot count each color pixel equally), might need to reinitialise at some point\\\\ \\ Target may leave out of the frame, there are a lot of objects in the scene\\ Stationary vs moving cameras\\ ID shift, move to another object\\ Moving background foreground and background are changing \\ \section*{L12 notes} \subsection*{Data driven image classification} Learning classifiers based on data\\ Train classifiers using KNN or DNN\\\\ \textbf{Challenges in CV}\\ Invariance and generalization \\\\ \textbf{Where deep learning comes in}\\ Every single image in orientation and shape\\ Extrapolate some form of semantics\\ \\ \textbf{AI}\\ Rule based system that uses expert indulge human intelligence \\ Narrow AI only do a dedicated task\\ Small sliver of human intelligence \\ Neurons are non linear processing unit \\ NN is not close to how the brain even works \\ Mainly done for statistical pattern recognition \\\\ Non linearity (Perceptron) are building blocks, weighting the sum which passes through a non-linear activation function \\ Features are formed with cascade of functions that transform features \\\\ \textbf{Perceptron Mark I}\\ Original perceptron was created to do image processing\\ Each photocell is sensitive to light\\ Wires are creating different combinations of inputs\\\\ Fully connected - Every single neuron has a connection to the output layer, weighted summation of every single pixel, each representing a probability of the class\\ \\ Locally connected instead of fully connected \\ Flatten the matrix into a vector, each pixel is 1 element in the vector which correspond to the input \\ Hidden units = input\_width $\times$ input\_height \\ Parameters for 1 hidden unit = Hidden unit ^2\) (+1 is negligible) \\\)\\ \textbf{Stationarity}\\ Definition of corners does not change\\ Relative comparison to the local neighbour hood upper left and bottom right\\ Apply same weights to to all neurons colored different \\ Otherwise we would need different weights\\ Every neuron is centered at every pixel\\ Square area is called the receptive field of the perceptron\\ If it has a reduction in half the dimension, receptive field at 3 $\times$ 3 will correspond to 6 $\times$ 6 in the original image\\ Will progressively increase even if kernel stay in same size due to reduce resolution \\\\ Perceptrons are using convolution operation - sweep the kernel over image \\ \\ Kernels whose weights are learned\\ Filtering extract edges, orientations of edges \\ E.g. Gabor, Sobel filter \\ Instead learn weights for the filters \\\\ \textbf{Feature maps}\\ Also called a channel\\ \\ NN also uses pooling rather than simply convolution \\ After pooling the resolution would be very coarse\\ Aggregate response into a simple value like downsampling \\ ReLu rectified to 0 \\ Convolution is done by many kernels rather than just 1, using parameter sharing \\ \\ ImageNet is 3 orders of magnitude larger than previous Nets \\ Top 1 = 100 - 1\\ Top 5 = As long as u have 5 of the classes in the top of the probabilities, it is also considered correct, top 5 most confident correspond to ground truth \\ \subsection*{Extended Image classification} Not only find out what it is, also where it is \end{document}
\documentclass[journal,12pt,twocolumn]{IEEEtran} % \usepackage{setspace} \usepackage{gensymb} \usepackage{siunitx} \usepackage{tkz-euclide} \usepackage{textcomp} \usepackage{standalone} \usetikzlibrary{calc} %\doublespacing \singlespacing %\usepackage{graphicx} %\usepackage{amssymb} %\usepackage{relsize} \usepackage[cmex10]{amsmath} %\usepackage{amsthm} %\interdisplaylinepenalty=2500 %\savesymbol{iint} %\usepackage{txfonts} %\restoresymbol{TXF}{iint} %\usepackage{wasysym} \usepackage{amsthm} %\usepackage{iithtlc} \usepackage{mathrsfs} \usepackage{txfonts} \usepackage{stfloats} \usepackage{bm} \usepackage{cite} \usepackage{cases} \usepackage{subfig} %\usepackage{xtab} \usepackage{longtable} \usepackage{multirow} %\usepackage{algorithm} %\usepackage{algpseudocode} \usepackage{enumitem} \usepackage{mathtools} \usepackage{steinmetz} \usepackage{tikz} \usepackage{circuitikz} \usepackage{verbatim} \usepackage{tfrupee} \usepackage[breaklinks=true]{hyperref} %\usepackage{stmaryrd} \usepackage{tkz-euclide} % loads TikZ and tkz-base %\usetkzobj{all} \usetikzlibrary{calc,math} \usepackage{listings} \usepackage{color} %% \usepackage{array} %% \usepackage{longtable} %% \usepackage{calc} %% \usepackage{multirow} %% \usepackage{hhline} %% \usepackage{ifthen} %% %optionally (for landscape tables embedded in another document): %% \usepackage{lscape} \usepackage{multicol} \usepackage{chngcntr} \usepackage{amsmath} \usepackage{cleveref} %\usepackage{enumerate} %\usepackage{wasysym} %\newcounter{MYtempeqncnt} \DeclareMathOperator*{\Res}{Res} %\renewcommand{\baselinestretch}{2} \renewcommand\thesection{\arabic{section}} \renewcommand\thesubsection{\thesection.\arabic{subsection}} \renewcommand\thesubsubsection{\thesubsection.\arabic{subsubsection}} \renewcommand\thesectiondis{\arabic{section}} \renewcommand\thesubsectiondis{\thesectiondis.\arabic{subsection}} \renewcommand\thesubsubsectiondis{\thesubsectiondis.\arabic{subsubsection}} % correct bad hyphenation here \hyphenation{op-tical net-works semi-conduc-tor} \def\inputGnumericTable{} %% \lstset{ %language=C, frame=single, breaklines=true, columns=fullflexible } %\lstset{ %language=tex, %frame=single, %breaklines=true %} \usepackage{graphicx} \usepackage{pgfplots} \begin{document} % \newtheorem{theorem}{Theorem}[section] \newtheorem{problem}{Problem} \newtheorem{proposition}{Proposition}[section] \newtheorem{lemma}{Lemma}[section] \newtheorem{corollary}[theorem]{Corollary} \newtheorem{example}{Example}[section] \newtheorem{definition}[problem]{Definition} %\newtheorem{thm}{Theorem}[section] %\newtheorem{defn}[thm]{Definition} %\newtheorem{algorithm}{Algorithm}[section] %\newtheorem{cor}{Corollary} \newcommand{\BEQA}{\begin{eqnarray}} \newcommand{\EEQA}{\end{eqnarray}} \newcommand{\define}{\stackrel{\triangle}{=}} \bibliographystyle{IEEEtran} %\bibliographystyle{ieeetr} \providecommand{\mbf}{\mathbf} \providecommand{\pr}[1]{\ensuremath{\Pr\left(#1\right)}} \providecommand{\qfunc}[1]{\ensuremath{Q\left(#1\right)}} \providecommand{\sbrak}[1]{\ensuremath{{}\left[#1\right]}} \providecommand{\lsbrak}[1]{\ensuremath{{}\left[#1\right.}} \providecommand{\rsbrak}[1]{\ensuremath{{}\left.#1\right]}} \providecommand{\brak}[1]{\ensuremath{\left(#1\right)}} \providecommand{\lbrak}[1]{\ensuremath{\left(#1\right.}} \providecommand{\rbrak}[1]{\ensuremath{\left.#1\right)}} \providecommand{\cbrak}[1]{\ensuremath{\left\{#1\right\}}} \providecommand{\lcbrak}[1]{\ensuremath{\left\{#1\right.}} \providecommand{\rcbrak}[1]{\ensuremath{\left.#1\right\}}} \theoremstyle{remark} \newtheorem{rem}{Remark} \newcommand{\sgn}{\mathop{\mathrm{sgn}}} \providecommand{\abs}[1]{\left\vert#1\right\vert} \providecommand{\res}[1]{\Res\displaylimits_{#1}} \providecommand{\norm}[1]{\left\lVert#1\right\rVert} %\providecommand{\norm}[1]{\lVert#1\rVert} \providecommand{\mtx}[1]{\mathbf{#1}} \providecommand{\mean}[1]{E\left[ #1 \right]} \providecommand{\fourier}{\overset{\mathcal{F}}{ \rightleftharpoons}} %\providecommand{\hilbert}{\overset{\mathcal{H}}{ \rightleftharpoons}} \providecommand{\system}{\overset{\mathcal{H}}{ \longleftrightarrow}} %\newcommand{\solution}[2]{\textbf{Solution:}{#1}} \newcommand{\solution}{\noindent \textbf{Solution: }} \newcommand{\cosec}{\,\text{cosec}\,} \providecommand{\dec}[2]{\ensuremath{\overset{#1}{\underset{#2}{\gtrless}}}} \newcommand{\myvec}[1]{\ensuremath{\begin{pmatrix}#1\end{pmatrix}}} \newcommand{\mydet}[1]{\ensuremath{\begin{vmatrix}#1\end{vmatrix}}} %\numberwithin{equation}{section} \numberwithin{equation}{subsection} %\numberwithin{problem}{section} %\numberwithin{definition}{section} \makeatletter \@addtoreset{figure}{problem} \makeatother \let\StandardTheFigure\thefigure \let\vec\mathbf %\renewcommand{\thefigure}{\theproblem.\arabic{figure}} \renewcommand{\thefigure}{\theproblem} %\setlist[enumerate,1]{before=\renewcommand\theequation{\theenumi.\arabic{equation}} %\counterwithin{equation}{enumi} %\renewcommand{\theequation}{\arabic{subsection}.\arabic{equation}} \def\putbox#1#2#3{\makebox[0in][l]{\makebox[#1][l]{}\raisebox{\baselineskip}[0in][0in]{\raisebox{#2}[0in][0in]{#3}}}} \def\rightbox#1{\makebox[0in][r]{#1}} \def\centbox#1{\makebox[0in]{#1}} \def\topbox#1{\raisebox{-\baselineskip}[0in][0in]{#1}} \def\midbox#1{\raisebox{-0.5\baselineskip}[0in][0in]{#1}} \vspace{3cm} \title{Matrix Theory (EE5609) Assignment 11} \author{Arkadipta De\\MTech Artificial Intelligence\\AI20MTECH14002} \maketitle \newpage %\tableofcontents \bigskip \renewcommand{\thefigure}{\theenumi} \renewcommand{\thetable}{\theenumi} \begin{abstract} This document proves that, each field of the characteristic zero contains a copy of the rational number field. \end{abstract} All the codes for the figure in this document can be found at \begin{lstlisting} https://github.com/Arko98/EE5609/blob/master/Assignment_11 \end{lstlisting} \section{\textbf{Problem}} Prove that, each field of the characteristic zero contains a copy of the rational number field. \section{\textbf{Solution}} The characteristic of a field is defined to be the smallest number of times one must use the field's multiplicative identity (1) in a sum to get the additive identity. If this sum never reaches the additive identity (0), then the field is said to have characteristic zero.\\ Let $\mathbb{Q}$ be the rational number field. Hence, \begin{align} 0 &\in \mathbb{Q} \qquad{\text{[Additive Identity]}}\\ 1 &\in \mathbb{Q} \qquad{\text{[Multiplicative Identity]}} \end{align} As addition is defined on $\mathbb{Q}$ hence we have, \begin{align} 1 &\not= 0\label{eq1}\\ 1+1 = 2 &\not= 0\label{eq2} \intertext{And so on,} 1+1+\dots+1 = n &\not= 0\label{eq3} \end{align} From the definition of characteristic of a field and from \eqref{eq1}, \eqref{eq2} and so on up-to \eqref{eq3}, the rational number field, $\mathbb{Q}$ has characteristic 0.\\ \begin{comment} Now, let $F$ be a field of characteristic 0. Hence we have, \begin{align} 0 &\in F \qquad{\text{[Additive Identity]}}\\ 1 &\in F \qquad{\text{[Multiplicative Identity]}} \end{align} Since the characteristic of $F$ is zero hence, \begin{align} 1 \not= 1+1 \not= 1+1+\dots \not= 0 \end{align} As $F$ is a field, it is closed under addition. Hence for addition of $n$ number of 1 we have, \begin{align} 1+1+\dots+1 = n \in F \end{align} And, \begin{align} n \not= 0 \end{align} If $\mathbb{Z}$ is the set of integers then we have, \begin{align} \mathbb{Z} \subseteq F \end{align} As $F$ is a field, every element in $F$ will have a multiplicative inverse, thus, \begin{align} \frac{1}{n} \in F \end{align} Also, $F$ is closed under multiplication and thus, \begin{align} \forall m,n \in \mathbb{Z} \quad{\text{and }} n \not= 0\\ m\cdot\frac{1}{n} \in F\\ \implies \frac{m}{n} \in F \intertext{Hence, if $\mathbb{Q}$ is the rational number field then,} \mathbb{Q} \subseteq F \end{align} Hence, proved that field $F$ contains a copy of the rational number field. \end{comment} \end{document}
\section{Last lecture} Finish off parton construction with quantum spin liquids and spend the last 20 minutes for an overview of what we did in the course and try to tie things together a bit. Fermionic parton construction. \begin{align} \vec{S} &= \begin{cases} \frac{1}{2}f^\dagger \vec{\sigma} f\\ \frac{1}{2}z^\dagger \vec{\sigma} z \end{cases} \end{align} We had spin operators with 2 states per site. And two flavours of fermions per site. We actually get 4 states per site for the fermions, but we deemed two of them unphysical, so that's how we describe the two initial states. So we have $\ket{\uparrow}=\ket{01}$ and $\ket{\downarrow}=\ket{10}$ which are physical states but the states $\ket{00}$ and $\ket{11}$ are not gauge invariant and hence unphysical. There is a $U(1)$ gauge redundancy that keeps physical operators invariant. \begin{align} f &\to e^{i\theta}f \end{align} Actually there is an $SU(2)$ gauge redundancy. To implement this gauge constraint, we need to enforce a constraint, which is that the number of particles per site should always be 1. \begin{align} n_1 + n_2 = 1 \end{align} So we're in the $01$ and $10$ subspace. If we decompose the operator this way and enforce the constraint, that gives us new mean-field approximations that we didn't have access to before. We started with the Heisenberg model, and rewrote it as just model of fermions hopping. \begin{align} H &= \sum_{ij} \vec{S}_i\cdot\vec{S}_j J_{ij}\\ &= \sum_{ij} \left[ -\frac{1}{2} J_{ij} f_{i\alpha}^\dagger f_{j\alpha} f_{j\beta}^\dagger f_{i\beta} + J_{ij} \left( \frac{1}{2}n_i - \frac{1}{4} n_i n_j \right) \right] \end{align} And, we can then write the ansatz that \begin{align} \chi_{ij} &= \langle f_{i\alpha}^\dagger f_{j\alpha}\rangle \end{align} which if we put nito the Hamiltonian gives the mean-field Hamiltonian \begin{align} H_{mf} &= \sum_{ij} \left[ \left( -\frac{1}{2} J_{ij} f_{i\alpha}^\dagger f_{i\alpha} \chi_{ji} +\mathrm{h.c.} \right) - \left| \chi_{ij} \right|^2 \right] \end{align} where we have replaced $f_{i\alpha}^\dagger f_{j\alpha}$ by the mean field. And for consistency, we want ot enforce the equation $ \chi_{ij} = \langle f_{i\alpha}^\dagger f_{j\alpha}\rangle$. The zeroth order thing to do is to not require this constraint exactly, but require it on average. So there is a zeroth order mean field which is to treat the constraint on average. One thing we can do is add an extra Lagrange mulitiplier in the Hamiltonian which acts like a chemical potential that fixes this average $\langle n_i \rangle = 1$. So we have \begin{align} H_{0-mf} &= H_{mf} + \sum_i a_0 \left( f_{i\alpha}^\dagger f_{i\alpha} - 1 \right) \end{align} so this is basically a site-dependent chemical potential to enforce $\langle n_i \rangle = 1$. We hvae this Hamiltonian that is afree-fermion Hamitonian, and we hvae thse parameters $a_0$ and $\chi$ we can tune, but we want to choose them to be self-consistent such. Choose $a_0$ such that $\langle n_i\rangle = 1$. We are assuming $\chi_{ij} &= \bar{\chi}_{ij}$ ad $a_0(i) = \bar{a}_0$ satisfy self-consistency equations. The fermions carry spin half but are electrically neutral. These excitations are electrically neutral spin-$\frac{1}{2}$ fermions. We call these fermionic \emph{spinons}, which are excitations that carry spin-$\frac{1}{2}$. Local excitaitons always carry integer spin, because every spin flip operation changes the spin by one, when it goes from $-\frac{1}{2}$ to $\frac{1}{2}$. Any logcal opeator can only create integer spin excitations, so a spin-$\frac{1}{2}$ is a non-trivial thing. They also happen to be electrically neutral fermions. The zeroth order mean field theory is useful because you can deduce you can have fermionic spinon excitations, but in some sense you can only treat the constrant on average, but you should rally treat hte constaint exactly. We don't know if hte meanf ifeld theory is stable to flutcuations either, which could be in phase or amplitude of the $\chi_{ij}$ mean field. Another way of arriving at the $\chi_{ij}$ is instead of doing a mean field theory is do a Hubbard-Stratonvich transformation, where you replace $\phi^4 \to \phi^2 \phi^2 + \chi^2$ completing the square. It's a common trick, but if you're familiar wiht it, just consider it a mean field hteory. \subsection{First-order mean field}c:w we consider a first-order mean field theory to check the stability of the zeroth order mean field and treat hte constraint exactly. The first fluctuations to consider are phase fluctuations. \begin{align} \chi_{ij} &= \bar{\chi}_{ij} e^{i a_{ij}} \end{align} The amplitude fluctuation is gapped due to the $|\chi_{ij}|^2$ term so we don't have to worry about it. A useful way of thinking about this is the integral language. \begin{align} Z &= \int \mathcal{D} f \mathcal{D} \bar{f}\, e^{iS} \prod_{i,t} \delta\left( f_i^\dagger f_i - 1 \right) \end{align} Every site and time has a delta function. And we can introduce fields $a_0(i, t)$ \begin{align} Z &= \int \mathcal{D} f \mathcal{D} \bar{f} \mathcal{D} a_0\, e^{i \sum_{i, t} a_0 (i, t)} \left( f_9^\dagger f_i - 1 \right) e^{iS} \end{align} and hte Hamiltonian becomes \begin{align} H_{1,mf} &= \sum_{ij} -\frac{1}{2} J_{ij} \left[ \left( f_{i\alpha}^\dagger f_{j\alpha} \bar{\chi}_{ji} e^{-ia_{ij}} + \mathrm{h.c.} \right) - \left| \bar{\chi}_{ij} \right|^2 \right] - \sum_{i} a_0\left( i \right) \left( f_{i\alpha}^\dagger f_{i\alpha} - 1 \right) \end{align} and now $a_0$ becomes a dynamical field. Then $a$ can be thought of as a $U(1)$ gauge field, with the transformation \begin{align} f_{i} &\to e^{i\theta_i} f_i\\ a_{ij} &\to a_{ij} + \theta_j - \theta_i \end{align} keeping it invariant. Then $a_0$ literally enters the theory as the time-componento f the gauge field. \begin{align} \mathcal{L} &= i \sum_{i} f_i^\dagger \left( \partial_t - i a_0 \right) f_i \end{align} So basically we get to fermionic spinons plus $U(1)$ gauge fields. We should emphases the gauge field is a dynamical emergent gauge field. It wasn't there microscopically, but once we do this decomposition, it has to be there due to the gauge redundancy, because we expanded the Hilbert space got expanded and we need to restrict it back down. The fluctuations of $\chi_{ij}$ correspond to the gauge field fluctuations. If we want to understand the stability of the mean-field ansatz, we need to understand the stability to fluctuations of this $U(1)$ gauge field. The stability of mean field is related to the stability to $U(1)$ gauge field fluctuations. There's lot to do in this direction, and you could consider all kinds of mean field ansatzs and you can go back to see that we have an $SU(2)$ gauge field fluctuations which are much larger, and you can put those in the theory which requires you to havea few more paramteres, so you can analyse all sorts of mean field theories. But now I want ot switch gears and not talk about hte Hamiltonian and the mean field gauge theory, but instead I want to talk about the wave functions. This leads to a whole class of trial wave functions, or variational wave functions, which are basically projected wave functions. This is a spatial component and this is a time component. Whence have this mean field ansatz, we have to look at the ground state \begin{align} \ket{\Psi_{\mathrm{mean}}\left( \chi_{ij} \right)} \end{align} which is the mean field state of partons. this mean field by itself is not a physical state because it doesn't live in the spin Hilbert space. Because it's a ground state of the zeroth order mean field theory, it contains unphysical states where there are 0 or 2 fermions per site. To get back into the original Hilbert space, we can take this mean field ground state and project it into the physical Hilbert space. \begin{align} \ket{\Psi_{\mathrm{phys}} &= P\ket{\Psi_{\mathrm{mean}}(\chi_{ij})} \end{align} where $P$ is the projection onto 1 particle-per-site states. This is called the Gutewillen projection. Start with the Fock vacuum $\ket{0}$ and add fermions, and take that inner product with the state. \begin{align} \Psi_{\mathrm{spin}}^{\left( \chi_{ij} \right)} \left( \left\{ \alpha_i \right\} \right) &= \bra{0} \prod_{i} f_{\alpha i} \Ket{\Psi_{\mathrm{mean}^{(\chi_{ij})}} \end{align} Consider a different ansatz \begin{align} \tilde{\chi}_{Ij} &= \chi_{ij} e^{i\left( \theta_i - \theta_j \right)} \end{align} which is the same as taking $f_i \to e^{i\theta_i} f_i$, so then \begin{align} \Psi_{\mathrm{spin}}^{\left( \tilde{\chi} \right)} &= e^{i\sum_i \theta_i} \Psi_{\mathrm{spin}}^{\left( \chi \right)} \end{align} and the only difference is the overall phase which is the same physical state. It's incredible that this class of wave functions is so incredibly rich. Fractional quantum hall states, quantum spin liquids, any exotic state you can write down parton construction, and then do mean field and then do a projection. We can not just get ground states, but also variational states for excited states. I can put some winding or fluctuation of $\chi$, then do some projection and get some candidate excited wave function. To do it more explicitly, I can do a spinon wave function. The spinon wave functions \begin{align} \Psi_{\mathrm{spin}}^{\mathrm{spinon}} \left( i_1, \lambda_1; i_2, \lambda_2 \right) &= \bra{0} \left( \prod_{i} f_{i,\alpha_i} \right) f_{i_1\lambda_1}^{\dagger} f_{i_2 \lambda_2} \ket{\Psi_{\mathrm{mean}}^{\chi}} \end{align} There's been a lot of work trying to write down new fancy wave functions using neural networks and tensor networks and machine learning, and PEPS and so on, but these are the ones that actually work, and describe everything. All the popular ones people talk about but are not nearly as powerful as this class of wave functions. Those other classes of wave functions are fun to think about they have not been as powerful so far as these wave functions. You set up this mean field theory, and you set up spins with spinons, that gets yo to $U(1)$ gauge field, and then you get wave functions by projection to the physical Hilbert space. Now you consider all sorts of mean field theories. $\chi$ and $a_0$ are the variational parameter. \begin{question} Have there improvmentes by including gague flucationas? \end{question} You can improve the wave functions by including gague fluctuations. It is an interesting reearch direction but I have seen very littel work. One thing cold be to get better wave functions by doing exactly that. At this point the name of hte game is to consider all sorts of mean field ansatzs and describe all sorts of phases. \section{$\ZZ_2$ spin liquid} There's another we of arriving at very similar states in terms of projected wave functions and mean field theory approach. One way is to assume the spinons form an $s$-wave superconductor. Assume when spinons form $s$-wave superconductor \begin{align} \langle f_{i\uparrow} f_{i\downarrow}\rangle &\ne 0 \end{align} The mean field wave function si going to be a mean field wave function for an $s$-wave superconductor, and then sou do a projection onto one particle per site. This gives a physical wave function in the Hilbert space, which si a $\ZZ_2$ spin liquid wave function. When this parton model acquires a non-zero expectation, there is an Anderson-Higgs gauge symmetry and what's left behind is this $\ZZ_2$ gauge theory. \begin{align} \ket{\Psi_{\ZZ_2 \mathrm{QSL}}} &= P \ket{\Psi_{\Psi_{mf,s\text{-wave s.c.}}}} \end{align} In parton mean field theory, $U(1)$ gauge field plus $f_{i,\alpha}$. And $U(1)$ breaks by Higgs to $\ZZ_2$. The $\ZZ_2$ gauge field coupled $f_{i,\alpha}$. Then we have topological excitations. The first kind of quasiparticle $f$ is BdG quasi-particles of $s$-wave conductor created by breaking ``cooper pairs`` of the neutral spin-half spinons. Each one is fermionic spin-$\frac{1}{2}$ excitations. The second kind. Instead of writing the mean field state you insert a vortex nito this $s$-wave superconductor. The $\pi$-flux vortex of an $s$-wave superconductor after projection becomes a vison, which we talked about in the context of the quantum dimer model, and in the context of the $\ZZ_2$ toric code vortex where this was the $m$ particle. This $f$ is a fermion and this $m$ particle is a boson. Every other topological class of excitations we could get from here. We could consider composite $f$ and $m$ particles, which gives what we would normally call the $e$ particle in the toric code state. The third kind of $f\times m = e$ When $f$ goes around $m$, that picks up a minus sign, I would pick up the spin of the $f$ which is minus $-1/2$, and I would pick up a spin of the $m$ which is $+1/2$ and then the composite is a boson. The fourth kind is local excitations. Even numbers of spinons. You need more work to show that two visons coming together is local, but I'll leave that for you to think about. The whole point is that this is another way of arriving at this $\ZZ_2$ spin liquid, but there is something which didn't come up previously. We see the fermion $f$ is a spinon that carries spin-$\frac{1}{2}$, whereas the vison does not carry spin-$\frac{1}{2}$. All particles in the toric code were spin-less, so this differs from the quantum dimer model discussion and $\ZZ_2$ toric code discussion due to the quantum numbers these excitations have under the $SO(3)$ rotations. This didn't exist in the previous discussions. It could have existed if we demanded the dimness had spin-$\frac{1}{2}$. It's distinct from the toric code in that the spinons carry spin-$\frac{1}{2}$, so this whole state carries symmetry fractionalization. All these particles carry fractional spin. You can think of a spin-liquid as a superconducting state of spinons. That's one way of thinking about a quantum $\ZZ_2$ spin liquid. There is another important class of states is fractional quantum Hall states, also known as fractional Chern insulators. We can do it in terms of spins but we don't have to. In terms of spins, you can think of the boson $b$. We don't necessarily there is full SO(3) full spin rotation symmetry. We can write \begin{align} b &= f_1 f_2 \end{align} which si basically the same thing as writing the spins as $S^\dagger &= f_1^\dagger f_2 = \tilde{f}_1 \tilde{f}_2$. In this description $U(1)$ gauge theory goes \begin{align} f_1 &\to e^{i\theta} f_1\\ f_2 &\to e^{-i\theta} f_2 \end{align} Each of these form some kind of insulating phase with Chern number 1. Consider mean field state where $f_1,f_2$ are each in Chern insulator with $C_1=C_2=1$. I want ot track the background external gauge field under which $b$ carries charge 1. So let $A$ be a background $U(1)$ gauge field, not to be confused with the internal emergent gauge field that emerges from the $U(1)$ gauge transformation. \begin{table}[h] \centering \begin{tabular}{ccc} & $q_a$ & $q_A$\\ $f_1$ & + 1 & 1\\ $f_2$ & -1 & 0 \end{tabular} \caption{z2spin} \label{tab:z2spin} \end{table} Imagine we have some effective Lagrangian \begin{align} \mathcal{L}_b &= \mathcal{L}\left( f_1, a + A \right) + \mathcal{L}\left( f_2, a \right) \end{align} $f_2$ is a sate which si a Chern insulator with Chern number 1. And it's coupled to this $a$ gague field. What's an effective Lagrangian for such a csitaution. You may not remember, but we covered this before, to introduce a $U(1)$ level Chern-Simons theory. We can write the effective theory as \begin{align} \mathcal{L}\left( f_2, a \right) &= -\frac{1}{4\pi} \alpha_{\mu} \partial_{\nu} \alpha_{\lambda} \epsilon^{\mu\nu\lambda} - \frac{1}{2\pi} \epsilon^{\mu\nu\lambda} a_{\mu} \partial_{\nu} a_{\lambda} \end{align} so then the current is \begin{align} j_{\mu}^{\left( f_2 \right)} &= \frac{1}{2\pi} \epsilon^{\mu\nu\lambda} \partial_\nu \alpha_{\lambda} \end{align} So this is also a Chern-insulator 1 state. \begin{align} \mathcal{L}\left( f_1, a + A \right) &= -\frac{1}{4\pi} \beta \, d\beta + \frac{1}{2\pi} \left( a + A \right) d\beta \end{align} If we only keep leading order terms in these gauge fields, \begin{align} \mathcal{L}_b &= -\frac{1}{4\pi} \alpha\, d\alpha - \frac{1}{4\pi} \beta\, d\beta + \frac{1}{2\pi} a\, d\left( \beta - \alpha \right) + \frac{1}{2\pi} A\, d\beta \end{align} The whole point of hte parton mean field ansatz is that you can treat all the gauge fluctuations perturbabitvely. If you summarised in one sentence the parton constution. Decomose the physcial operaotrs in temrso f p Then aassume some mean field state, then assume fluctuiatons are weak. We assume the gague fluctuiaotns are greated perturbabilty, and all subleadng terms are irrelevant. And then we can just integrate out the $a$. And because thsi si a free theory, we can just solve the equation of motion for $a$. Either way you're going to get the same thing. \begin{align} \epsilon^{\mu\nu\lambda} \partial_\nu \beta_{\lambda} = \epsilon^{\mu\nu\lambda} \partial_\nu a_\lambda \end{align} which assuming it's not topologically weird space, \begin{align} \beta_{\mu} &= a_\mu + \partial_\mu \phi \end{align} and we can just ignore the second term, and we arrive at \begin{align} \mathcal{L}_b &= -\frac{2}{4\pi} \alpha\, d\alpha + \frac{1}{2\pi}A\, d\alpha \end{align} and we saw this before. This is $U(1)$ level 2 CS theory or $U(1)_2$. And you will find the Hall conducatnce is \begin{align} \sigma_H &= \frac{1}{2} \frac{1}{2\pi} \end{align} and so this ansatz describes a fractional quantum Hall state. \begin{question} Why is that $1$ and $0$ is a choice in the charge table? \end{question} In ternral you could have $a_{A1}$ and $q_{A2}$, but all you need is $q_{A1}+q_{A2}=1$. In that case your Lagrangian will be \begin{align} \mathcal{L}_b &= -\frac{2}{4\pi} \alpha\, d\alpha + \frac{1}{2\pi}A\, d\alpha + \frac{1}{2\pi} A\, \alpha \left( q_{A1} \beta + q_{A2} \alpha \right) \end{align} But in consdensed matter physics, people are find not worrying about global issues, and you could just wirte $\frac{1}{2}$ and $\frac{1}{2}$, but field theorists yell at me to write $1$ and $0$. But the correct thing to do is do the field throeeists integer charge $1$ and $0$. You'll get the same answer for the Hall conducatnce eithere way. They mess aorund with the global compactness of the gauge field. If you don't worry about non-trivial topologies you won't worry about this issue. Now you can also write down the wave funciton. Each mena field state is in some Chern number 1. Now the projection. We have two flavours of fermions. \begin{align} \Psi\left( \left\{ r_i \right\} \right) &= P_{n_1=n_2} \Phi_{C=1}\left( \left\{ r_i^2 \right\} \right) \Phi_{C=1}\left( \left\{ r_i^1 \right\} \right)\\ &= \left( \Phi_{c=1}\left( \left\{ r_i \right\} \right) \right)^2 \end{align} If you're familiar with this, this is the $\frac{1}{2}$-Laughlin FQH wave function. \begin{question} ??? \end{question} It's again the same thing, you identify $\ket{0}_b=\ket{00}$ and $\ket{1}_b=\ket{11}$ sa the physical states and $\ket{10}$ and $\ket{01}$ as non-phsyical. This parton construction is much better than the other approaches, because it unifies quantum spin liquids and quanutm Hall states. \begin{question} How did you get to the fact I need to consider 2 Chern nisulators? \end{question} In principle, there's an infinite numbero f mean field ansatz options, but why did I decide on the ansatz $b=f_1f_2$? The parton construciton is a way of describing any phase with an emergent gauge theory, even if gapless. When you do MF, you can consider many ansatzs. You can just pick one, see what its energetics looks like, and the one with least energy is the most likely. You can consdier all sorts of mean field ansatz whcih gives you many variational wave functions,a nd that gives you many. How did Laughlin know it's a square or cube of the free fermion wave function? It was just his guess based on his experience. \begin{question} How general is this? If you write $b=$ 3 fermions? \end{question} You could do in general $b=f_1f_2\cdots f_k$. the gauge symmetry is different, but you can still do it. You end up with $U(1)_k$ CS theory, if you assume all are in $C=1$ Chern-insulator states. \begin{question} Math procedure for free fermion model and mean field ansatz to output some topolgocial orderd satte. \end{question} There probably is one, but it hasn't been elucidated. Perhaps there's something more formal that can be developed. \section{Summary} I want to give you an overview of what we covered. A brief review of what we've done and why it all fits together. There's a lot more things to cover for another course. There are important things we didn't cover, like the algebraic theory of anyons, this modular tensor category. I can give another lecture about modular tensor categories, but since the lectures for the course are over we don't technically have to do that. Are you interested in a bonus lecture on Wednesday? Let me try to take 10 minutes to give you a summary or overview. We start off by talking about general htings, like locality in quantu mssytesm, how gapped implies correlation length. We didn't directly do naything wiht these, but we talked about Hilbert spaces decompsoing into local tensor products. We did use finite correlation lneght in some places. Then we described TQFTs with path integrals $Z\left( M^{d+1} \right)$, but the important point is that topologicla phases of matter are believed to be in 1-1 correspondtance to deformaiton clases of TQFTs. An important distinction was the notion of invertible vs non-invertible. Invertible in this contextz means that $|Z|=1$ and non-invertible menas $|Z|\ne 1$. Invertible means unique ground state, but non-invertible means degenerate ground states. We did some examples of TQFTs. They came in two flavours. We talked about this, but there was $U(1)_k$ CS theory, which came in two flavours. We could think of this as a response theory, meaning that we have a background gauge field $Z\left( M^3, A \right) = Z\left( M^3, 0 \right) e^{i k S_{CS}[A]}$. This can describe Chern insulator integer quantum Hall states, in other words invertible topological phase. Then the way of thinking about it is that we have a dynamical gauge theory. Here, we're actually integrating over all gauge field configurations. \begin{align} Z\left( M^3 \right) &= \int \mathcal{D} a\, e^{ikS_{CS}(a)} \end{align} and this describes non-invertible topological phases, like fractional quantum Hall states, quantum spin liquids. One of the problems is thinking about the toric code in terms of CS theories with 2 by 2 matrices. It depends on whether you treat the gauge field as background or dynamical. Another example is SPT path integrals, or Digraph-Witten theory, where you pick a cohomology class inside a cohomology group \begin{align} \left[ \nu_{d + 1} \right] \in H^{d + 1} \left( G, U(1) \right) \end{align} You can think of it as an invertible TQFT \begin{align} Z\left( M^{d+1}, A \right) &= e^{i\int_M A^* \nu_{d+1}} \end{align} We triangulated our manifold, and defined group elements on links, and the path integral value was always a phase. This describes SPTs. One utility of this construction was that it gave exact wave functions, and it gives parent Hamiltonians, a full solvable model to describe a huge class of SPTs. And remember SPTs are a subset of invertible phases. An invertible phase is a subset that is invertible on all manifolds. In a ground states of an invertible topological state, it has an inverse state that if you stack them can adiabatically go to a trivial state. If you don't care about the symmetry, you can always adiabatically connect it to a trivial state, but not if you want to respect the symmetry. Then here what we can do is consider non-invertible TQFTs, \begin{align} Z(M) \propto \sum_{[a]} e^{i \int a^* \nu} \end{align} where the sum of over all flat gauge fields. If you take $G=\ZZ_2$ and $[\nu] = [0]$, then this describes the $\ZZ_2$ spin liquid, which is the toric code. There's one other example that we did, which was the TQFT for the $(1+1$-D Majorana. We had a path integral over a 2D manifold with a 2-dimensional spin structure. \begin{align} Z\left( M^2, S \right) &= \left( -1 \right)^{\Arf(S)} \end{align} And then we talked about concrete examples of topological phases. We had the $(1+1)$D Majorana. Then we talked about the $(2+1)D$ Chern insulator, TRI TI and $p+ip$ superconductor. The invertible free fermion model. Time-reversal invariant topological insulator. We talked about the $(3+1)$D TRI TI. Then we tlked about boson SPTs, including the AKLT construction, and group cohomology models. Then we talked about non-invertible topological phases, which includes quantum spin liquids, including quantum dimer models, parton construction, lattice gauge thoery and toric code. FQH state $U(1)_k$ CS theory by parton construction. Thep oint of the anyon pahses was topological excitations wiht fractional statistics. We had topological ground state degeneracies that depended on the topology of the manifold and so on. In practice, this class is a survey of the huge classes of topological phaes. It's a deep and rich subject. In the next bonus lecture, I'll tell you about non-Abelian topological phaes and the algebraic theory.
\section{Task 4} The attached program will map the function $\symbol{92} x -> (x/(x-2.3))^3$ unto the array $[1,..,753411]$ both sequanteially and using a CUDA kernel for doing it in parallel. Both runs are timed and the results are compared to verify that the CPU and GPU are agreeing on the result. For all the runs I did the results we're close enough to satisfy the above function. The timing is done only for the calculation and not copying data to the graphics cards or allocating memory. The verification of the results is done using the following check $\text{abs}(cpu_t - gpu_t) < \epsilon$. All test runs was run on one of the compute machines we we're granted access to as part of the course. \begin{table} \center \begin{tabular}{|c|c|c|} \hline \textbf{Array Size} & \textbf{CPU Time} & \textbf{GPU Time} \\\hline 100 & 50 & 63 \\ 200 & 90 & 65 \\ 300 & 73 & 66 \\ 400 & 82 & 65 \\ 500 & 91 & 103 \\ 600 & 130 & 107 \\ 700 & 111 & 105 \\ 800 & 120 & 80 \\ 900 & 152 & 80 \\ 1000 & 143 & 76 \\ 1100 & 144 & 77 \\ 1300 & 162 & 68 \\ 1500 & 184 & 150 \\ 2000 & 247 & 77 \\ 3000 & 360 & 75 \\ 5000 & 482 & 77 \\ 10000 & 1122 & 95 \\ 15000 & 1320 & 80 \\ 50000 & 5657 & 149 \\ 100000 & 8233 & 173 \\ 150000 & 12266 & 244 \\ 200000 & 16357 & 278 \\ 250000 & 20409 & 341 \\ 300000 & 24426 & 356 \\ 350000 & 28524 & 434 \\ 400000 & 32492 & 444 \\ 500000 & 42428 & 578 \\ 600000 & 48733 & 635 \\ 700000 & 56853 & 747 \\ 753411 & 61204 & 806 \\\hline \end{tabular} \caption{The runtimes reported by the program, measured in microseconds.} \label{tab:times} \end{table} The timing results for different array sizes are shown in Table \ref{tab:times} and shows that the CPU generally are only faster at very small array sizes. According to my measurements already between 100-200 elements, the GPU code runs faster than the sequential CPU code. Furthermore the increase in compute time rises a lot faster for the CPU code compared to the GPU version. The reason the GPU is so much faster as the number of iterations increase is because of it's ability to process 1024 different ``iterations'' of the sequential loop in parallel. Since the measurements are in microseconds on a time shared machine there was some inaccuracies, the values in Table \ref{tab:times} is the average of running the program 5 times after each other.
%------------------------- % Resume in Latex % Author : Sourabh Bajaj % Modified by: Ryan P Smith % License : MIT %------------------------ %------------------------------------------- %%%%%% IMPORT PREAMBLE %%%%%%%%%%%%%%%%%%%%%%%%%%% \RequirePackage{preamble} %------------------------------------------- %%%%%% CV STARTS HERE %%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{document} %----------HEADING----------------- \begin{tabular*}{\textwidth}{l@{\extracolsep{\fill}}r} \textbf{{\Large Ryan P Smith}} & \textbf{Denver, CO} \\ \href{http://www.linkedin.com/in/rpseq}{linkedin.com/in/rpseq} & \href{mailto:ryan.smith.p@gmail.com}{ryan.smith.p@gmail.com} \\ \href{https://github.com/RPSeq}{github.com/rpseq} & +1-319-899-0190 \\ \end{tabular*} %--------INTERESTS------------ \section{About Me} \small{Passionate about learning and developing new technologies as well as tinkering with complex systems---especially software infrastructure and automation. After 7 years of bioinformatics and computing work in academia, I am seeking roles in DevOps, infrastructure, and data engineering. I am an extremely fast learner and given the opportunity, I can rapidly become an expert in any technology. This resume is a mini DevOps project, auto-built using \href{https://circleci.com/gh/RPSeq/resume}{CircleCI.}} \resumeSubHeadingListStart \resumeItem{Relevant Interests} {DevOps, continuous integration, Kubernetes, distributed computing, AWS, GCP, containers, automation, object-oriented and functional programming, data enginering, bioinformatics} \resumeSubHeadingListEnd %-----------EXPERIENCE----------------- \section{Experience} \resumeSubHeadingListStart \resumeSubheading {Circle Computer Resources, Inc.}{Cedar Rapids, IA} {Remote IT Procurement Specialist}{November 2018 -- Present} \resumeItemListStart \resumeItem{IT Procurement} {Temporary full-time contract job. Secure reliable internet services for small businesses in hard-to-reach areas. Specialize in WISPs providing service to regions with poor cable, DSL or fiber coverage. Negotiate with ISPs for service to meet our clients' needs.} \resumeItemListEnd \resumeSubheading {Girihlet, Inc., Oakland Genomics Center}{Oakland, CA} {Data Analyst}{Aug 2018 -- Sep 2018} \resumeItemListStart \resumeItem{Bioinformatics} {Provide a quality control dashboard for Illumina short read data. General Bash, Python, and Perl scripting to automate mitochondrial genome variant calling.} \resumeItem{Information Technology} {Upgrade and maintain the Oakland Genomics Center wireless and LAN networks. Maintain two on-premises CentOS servers for data processing and web hosting (Apache, NGINX)} \resumeItemListEnd \resumeSubheading {The McDonnell Genome Institute, Washington University}{St Louis, MO} {Graduate Research Scientist, Ira Hall Lab, Computational Genetics}{Feb 2015 -- Present} \resumeItemListStart \resumeItem{Distributed Computing, Bioinformatics} {Process and analyze population-level genome sequencing data to improve our understanding of the causes and consequences of structural variation in human genomes. Most work is done in a Linux environment with custom Bash pipelines, distributed across a Dockerized computing cluster. Pipelines often use bioinformatics tools combining Bayesian statistics and machine learning approaches, packaged in isolated Docker containers.} \resumeItem{Single-cell Sequencing} {Develop novel computational and molecular biology methods to sequence the genomes of single mammalian neurons, in collaboration with the Scripps Research Institute at University of California, San Diego. Typically process up to 10 TB of raw Illumina sequencing data within a 36 hour period.} \resumeItem{Teaching Assistant} {Advise students in characterizing the genome sequences of unknown bacteriophages. Hands-on computer lab course using a series of bioinformatics tools to identify genes and predict their function, as well as classifying novel phages into existing phylogenetic groups.} \resumeItemListEnd \resumeSubheading {University of Iowa}{Iowa City, IA} {Undergraduate Research Fellow, Adam Dupuy Lab, Cancer Genetics}{Aug 2010 -- May 2014} \resumeItemListStart \resumeItem{Genome Editing} {Designed methods for viral genetic engineering in mouse models of human cancers and a sequencing method for detecting resulting transgene insertions.} \resumeItem{Bioinformatics} {Processed high-throughput genome sequencing data using Linux bioinformatics tools followed by ad-hoc statistical analyses and data visualization in Python and R.} \resumeItemListEnd \resumeSubHeadingListEnd %--------PROGRAMMING SKILLS------------ \section{Programming Skills} \resumeSubHeadingListStart \resumeItem{Languages} {Bash, Python, R (ggplot), awk, SQL, C++, \LaTeX, Mathematica} \resumeItem{Technologies} {Linux/Unix, AWS, sed, git, Docker, Kubernetes, CircleCI, IBM Platform LSF, Oracle Grid Engine} \resumeSubHeadingListEnd %-----------EDUCATION----------------- \section{Education} \resumeSubHeadingListStart \resumeSubheading {Washington University}{St Louis, MO} {MA, Molecular Genetics and Genomics}{Aug. 2014 -- May 2018} \resumeSubheading {University of Iowa}{Iowa City, IA} {BS, Microbiology and Informatics; GPA: 3.7}{Aug. 2009 -- May 2014} \resumeItemListStart \resumeItem{Relevant Coursework} {Intro to Computer Science, Programming for Informatics, Biostatistics, Programming with C++, Bioinformatics Techniques, Networking and Security, Human Computer Interaction, Database Management, Strategic Management of Technology, Informatics Capstone Project} \resumeItemListEnd \resumeSubHeadingListEnd %--------Publications------------ %\section{Publications} % \resumeSubHeadingListStart % % \publicationItem{Jennifer L. Hazen, Michael A. Duran, Ryan P. Smith*, Alberto R. Rodriguez, Greg S. Martin, Sergey Kupriyanov, Ira M. Hall, Kristin K. Baldwin} % { ``Using Cloning to Amplify Neuronal Genomes for Whole-Genome Sequencing and Comprehensive Mutation Detection and Validation'' Genomic Mosaicism in Neurons and Other Cell Types. Neuromethods, vol 131. September 2017}{https://doi.org/10.1007/978-1-4939-7280-7\_9} % % \publicationItem{Ryan P. Smith*, Jesse D. Riordan, Charlotte R. Feddersen, Adam J. Dupuy} % { ``A Hybrid Adenoviral Vector System Achieves Efficient Long-term Gene Expression in the Liver via PiggyBac Transposition'' Human Gene Therapy, 26(6):377-85. June 2015}{https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4492551/} % % \publicationItem{Jesse D. Riordan, Luke Drury, Ryan P. Smith*, Ben T. Brett, Adam J. Dupuy} % { ``Sequencing Methods and Datasets to Improve Functional Interpretation of Sleeping Beauty Mutagenesis Screens'' BMC Genomics, 15(1): 1150. December 2014}{https://www.ncbi.nlm.nih.gov/pubmed/25526783} % % \resumeSubHeadingListEnd %------------------------------------------- \end{document}
\documentclass{article} \usepackage{listings} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage[hyphens]{url} \usepackage{hyperref} \begin{document} %\paragraph{2-Programming and Indie Staff information} \paragraph{Course code:} FGA2.GT1-03 (Physics) \paragraph{Academic year:} 2013-2014 \paragraph{Lecturer:} Giuseppe Maggiore \paragraph{Contact info:} \href{mailto:maggiore.g@ade-nhtv.nl}{maggiore.g@ade-nhtv.nl} \paragraph{Appointment day:} Friday, all day, in the IGAD programming teachers' room (N1.308) at the main building \end{document}
\hypertarget{cleaning-and-validation}{% \chapter{Cleaning and Validation}\label{cleaning-and-validation}} \hypertarget{introduction}{% \section{Introduction}\label{introduction}} This is the first in a series of notebooks that make up a \href{https://allendowney.github.io/PoliticalAlignmentCaseStudy/}{case study in exploratory data analysis}. This case study is part of the \href{https://allendowney.github.io/ElementsOfDataScience/}{\emph{Elements of Data Science}} curriculum. In this notebook, we \begin{enumerate} \def\labelenumi{\arabic{enumi}.} \item Read data from the General Social Survey (GSS), \item Clean the data, particularly dealing with special codes that indicate missing data, \item Validate the data by comparing the values in the dataset with values documented in the codebook. \item Generate ``resampled'' datasets that correct for deliberate oversampling in the dataset, and \item Store the resampled data in a binary format (HDF5) that makes it easier to work with in the notebooks that follow this one. \end{enumerate} The following cell loads the packages we need. If you have everything installed, there should be no error messages. \begin{lstlisting}[language=Python,style=source] import pandas as pd import numpy as np import matplotlib.pyplot as plt import seaborn as sns \end{lstlisting} \hypertarget{reading-the-data}{% \section{Reading the data}\label{reading-the-data}} The data we'll use is from the General Social Survey (GSS). Using the \href{https://gssdataexplorer.norc.org/projects/52787}{GSS Data Explorer}, I selected a subset of the variables in the GSS and made it available along with this notebook. The following cell downloads this extract. \begin{lstlisting}[language=Python,style=source] from os.path import basename, exists def download(url): filename = basename(url) if not exists(filename): from urllib.request import urlretrieve local, _ = urlretrieve(url, filename) print('Downloaded ' + local) download('https://github.com/AllenDowney/PoliticalAlignmentCaseStudy/' + 'raw/master/gss_eda.tar.gz') \end{lstlisting} The data is in a gzipped tar file that contains two files: \begin{itemize} \item \passthrough{\lstinline!GSS.dat!} contains the actual data, and \item \passthrough{\lstinline!GSS.dct!} is the ``dictionary file'' that describes the contents of the data file. \end{itemize} The dictionary file is in Stata format, so we'll use the \passthrough{\lstinline!statadict!} library to read it. The following cell installs it if necessary. \begin{lstlisting}[language=Python,style=source] try: import statadict except ImportError: !pip install statadict \end{lstlisting} We can use the Python module \passthrough{\lstinline!tarfile!} to extract the dictionary file, and \passthrough{\lstinline!statadict!} to read and parse it. \begin{lstlisting}[language=Python,style=source] import tarfile from statadict import parse_stata_dict filename = 'gss_eda.tar.gz' dict_file='GSS.dct' data_file='GSS.dat' with tarfile.open(filename) as tf: tf.extract(dict_file) stata_dict = parse_stata_dict(dict_file) stata_dict \end{lstlisting} \begin{lstlisting}[style=output] <statadict.base.StataDict at 0x7f18f62888d0> \end{lstlisting} The result is a \passthrough{\lstinline!StataDict!} object that contains the names of the columns in the data file and the column specifications, which indicate where each column is. We can pass these values to \passthrough{\lstinline!read\_fwf!}, which is a Pandas function that reads \href{https://en.wikipedia.org/wiki/Flat-file_database}{fixed width files}, which is what \passthrough{\lstinline!GSS.dat!} is. \begin{lstlisting}[language=Python,style=source] with tarfile.open(filename) as tf: fp = tf.extractfile(data_file) gss = pd.read_fwf(fp, names=stata_dict.names, colspecs=stata_dict.colspecs) \end{lstlisting} The column names in the data file are in all caps. I'll convert them to lower case because I think it makes the code look better. \begin{lstlisting}[language=Python,style=source] gss.columns = gss.columns.str.lower() \end{lstlisting} We can use \passthrough{\lstinline!shape!} and \passthrough{\lstinline!head!} to see what the \passthrough{\lstinline!DataFrame!} looks like. \begin{lstlisting}[language=Python,style=source] print(gss.shape) gss.head() \end{lstlisting} \begin{lstlisting}[style=output] (64814, 169) \end{lstlisting} \begin{tabular}{lrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr} \toprule {} & year & id\_ & agewed & divorce & sibs & childs & age & educ & paeduc & maeduc & speduc & degree & padeg & madeg & spdeg & sex & race & res16 & reg16 & srcbelt & partyid & pres04 & pres08 & pres12 & polviews & natspac & natenvir & natheal & natcity & natcrime & natdrug & nateduc & natrace & natarms & nataid & natfare & spkath & colath & libath & spkhomo & colhomo & libhomo & cappun & gunlaw & grass & relig & fund & attend & reliten & postlife & pray & relig16 & fund16 & sprel16 & prayer & bible & racmar & racpres & affrmact & happy & hapmar & health & life & helpful & fair & trust & conclerg & coneduc & confed & conpress & conjudge & conlegis & conarmy & satjob & class\_ & satfin & finrela & union\_ & fepol & abany & chldidel & sexeduc & premarsx & xmarsex & homosex & spanking & fear & owngun & pistol & hunt & phone & memchurh & realinc & cohort & marcohrt & ballot & wtssall & adults & compuse & databank & wtssnr & spkrac & spkcom & spkmil & spkmslm & colrac & librac & colcom & libcom & colmil & libmil & colmslm & libmslm & natcrimy & racopen & divlaw & teensex & pornlaw & letdie1 & polopts & natroad & natsoc & natmass & natpark & natchld & natsci & natenrgy & natspacy & natenviy & nathealy & natcityy & natdrugy & nateducy & natracey & natarmsy & nataidy & natfarey & confinan & conbus & conlabor & conmedic & contv & consci & abdefect & abnomore & abhlth & abpoor & abrape & absingle & god & reborn & savesoul & relpersn & sprtprsn & relexp & relactiv & fechld & fepresch & fefam & fejobaff & discaffm & discaffw & fehire & meovrwrk & avoidbuy & income & rincome & realrinc & china \\ \midrule 0 & 1972 & 1 & 0 & 0 & 3 & 0 & 23 & 16 & 10 & 97 & 97 & 3 & 0 & 7 & 7 & 2 & 1 & 5 & 2 & 3 & 2 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 4 & 2 & 0 & 0 & 0 & 0 & 1 & 0 & 3 & 3 & 2 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 2 & 1 & 0 & 3 & 0 & 2 & 0 & 2 & 2 & 3 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 3 & 3 & 3 & 3 & 0 & 0 & 0 & 2 & 0 & 4 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 18951.0 & 1949 & 0 & 0 & 0.4446 & 1 & 0 & 0 & 1.0 & 0 & 1 & 0 & 0 & 0 & 0 & 5 & 2 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 1 & 1 & 1 & 1 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0.0 & -1 \\ 1 & 1972 & 2 & 21 & 2 & 4 & 5 & 70 & 10 & 8 & 8 & 12 & 0 & 0 & 0 & 1 & 1 & 1 & 6 & 3 & 3 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 5 & 1 & 0 & 0 & 0 & 0 & 1 & 0 & 2 & 2 & 7 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 1 & 0 & 3 & 0 & 3 & 0 & 1 & 2 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 3 & 2 & 4 & 0 & 0 & 0 & 3 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 24366.0 & 1902 & 1923 & 0 & 0.8893 & 2 & 0 & 0 & 1.0 & 0 & 2 & 0 & 0 & 0 & 0 & 4 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 2 & 1 & 2 & 1 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0.0 & -1 \\ 2 & 1972 & 3 & 20 & 2 & 5 & 4 & 48 & 12 & 8 & 8 & 11 & 1 & 0 & 0 & 9 & 2 & 1 & 6 & 3 & 3 & 3 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 5 & 2 & 0 & 0 & 0 & 0 & 1 & 0 & 1 & 2 & 4 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 1 & 0 & 2 & 0 & 1 & 0 & 2 & 1 & 2 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 2 & 2 & 1 & 3 & 0 & 0 & 0 & 2 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 24366.0 & 1924 & 1944 & 0 & 0.8893 & 2 & 0 & 0 & 1.0 & 0 & 2 & 0 & 0 & 0 & 0 & 4 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 1 & 1 & 1 & 1 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0.0 & -1 \\ 3 & 1972 & 4 & 24 & 2 & 5 & 0 & 27 & 17 & 16 & 12 & 20 & 3 & 3 & 1 & 4 & 2 & 1 & 6 & 0 & 3 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 5 & 2 & 0 & 0 & 0 & 0 & 1 & 0 & 5 & 9 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 1 & 0 & 3 & 0 & 2 & 0 & 2 & 2 & 2 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 3 & 3 & 3 & 0 & 0 & 0 & 2 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 30458.0 & 1945 & 1969 & 0 & 0.8893 & 2 & 0 & 0 & 1.0 & 0 & 1 & 0 & 0 & 0 & 0 & 4 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 2 & 2 & 1 & 1 & 1 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0.0 & -1 \\ 4 & 1972 & 5 & 22 & 2 & 2 & 2 & 61 & 12 & 8 & 8 & 12 & 1 & 0 & 0 & 1 & 2 & 1 & 3 & 3 & 3 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 4 & 2 & 0 & 0 & 0 & 0 & 1 & 0 & 1 & 2 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 2 & 1 & 0 & 2 & 0 & 2 & 0 & 2 & 2 & 2 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 2 & 1 & 4 & 0 & 0 & 0 & 2 & 0 & 3 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 50763.0 & 1911 & 1933 & 0 & 0.8893 & 2 & 0 & 0 & 1.0 & 0 & 1 & 0 & 0 & 0 & 0 & 5 & 2 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 1 & 1 & 1 & 1 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0.0 & -1 \\ \bottomrule \end{tabular} This dataset has 64814 rows, one for each respondent, and 166 columns, one for each variable. \hypertarget{validation}{% \section{Validation}\label{validation}} Now that we've got the data loaded, it is important to validate it, which means checking for errors. The kinds of errors you have to check for depend on the nature of the data, the collection process, how the data is stored and transmitted, etc. For this dataset, there are three kinds of validation we'll think about: \begin{enumerate} \def\labelenumi{\arabic{enumi})} \item We need to check the \textbf{integrity} of the dataset; that is, whether the data were corrupted or changed during transmission, storage, or conversion from one format to another. \item We need to check our \textbf{interpretation} of the data; for example, whether the numbers used to encode the data mean what we think they mean. \item We will also keep an eye out for \textbf{invalid} data; for example, missing data might be represented using special codes, or there might be patterns in the data that indicate problems with the survey process and the recording of the data. \end{enumerate} In a different dataset I worked with, I found a surprising number of respondents whose height was supposedly 62 centimeters. After investigating, I concluded that they were probably 6 feet, 2 inches, and their heights were recorded incorrectly. Validating data can be a tedious process, but it is important. If you interpret data incorrectly and publish invalid results, you will be embarrassed in the best case, and in the worst case you might do real harm. See \href{https://www.vox.com/future-perfect/2019/6/4/18650969/married-women-miserable-fake-paul-dolan-happiness}{this article} for a recent example. However, I don't expect you to validate every variable in this dataset. Instead, I will demonstrate the process, and then ask you to validate one additional variable as an exercise. The first variable we'll validate is called \passthrough{\lstinline!polviews!}. It records responses to the following question: \begin{quote} We hear a lot of talk these days about liberals and conservatives. I'm going to show you a seven-point scale on which the political views that people might hold are arranged from extremely liberal--point 1--to extremely conservative--point 7. Where would you place yourself on this scale? \end{quote} You can \href{https://gssdataexplorer.norc.org/projects/52787/variables/178/vshow}{read the documentation of this variable in the GSS codebook}. The responses are encoded like this: \begin{lstlisting}[style=output] 1 Extremely liberal 2 Liberal 3 Slightly liberal 4 Moderate 5 Slghtly conservative 6 Conservative 7 Extremely conservative 8 Don't know 9 No answer 0 Not applicable \end{lstlisting} The following function, \passthrough{\lstinline!values!}, takes a Series that represents a single variable and returns the values in the series and their frequencies. \begin{lstlisting}[language=Python,style=source] def values(series): """Count the values and sort. series: pd.Series returns: series mapping from values to frequencies """ return series.value_counts().sort_index() \end{lstlisting} Here are the values for the variable \passthrough{\lstinline!polviews!}. \begin{lstlisting}[language=Python,style=source] column = gss['polviews'] \end{lstlisting} \begin{lstlisting}[language=Python,style=source] values(column) \end{lstlisting} \begin{tabular}{lr} \toprule {} & polviews \\ \midrule 0 & 6777 \\ 1 & 1682 \\ 2 & 6514 \\ 3 & 7010 \\ 4 & 21370 \\ 5 & 8690 \\ 6 & 8230 \\ 7 & 1832 \\ 8 & 2326 \\ 9 & 383 \\ \bottomrule \end{tabular} To check the integrity of the data and confirm that we have loaded it correctly, we'll do a ``spot check''; that is, we'll pick one year and compare the values we see in the dataset to the values reported in the codebook. We can select values from a single year like this: \begin{lstlisting}[language=Python,style=source] one_year = (gss['year'] == 1974) \end{lstlisting} And look at the values and their frequencies: \begin{lstlisting}[language=Python,style=source] values(column[one_year]) \end{lstlisting} \begin{tabular}{lr} \toprule {} & polviews \\ \midrule 1 & 22 \\ 2 & 201 \\ 3 & 207 \\ 4 & 564 \\ 5 & 221 \\ 6 & 160 \\ 7 & 35 \\ 8 & 70 \\ 9 & 4 \\ \bottomrule \end{tabular} If you \href{https://gssdataexplorer.norc.org/projects/52787/variables/178/vshow}{compare these results to the values in the codebook}, you should see that they agree. \textbf{Exercise:} Go back and change 1974 to another year, and compare the results to the codebook. \hypertarget{missing-data}{% \section{Missing data}\label{missing-data}} For many variables, missing values are encoded with numerical codes that we need to replace before we do any analysis. For \passthrough{\lstinline!polviews!}, the values 8, 9, and 0 represent ``Don't know'', ``No answer'', and ``Not applicable''. ``Not applicable'' usually means the respondent was not asked a particular question. To keep things simple, we'll treat all of these values as equivalent, but we lose some information by doing that. For example, if a respondent refuses to answer a question, that might suggest something about their answer. If so, treating their response as missing data might bias the results. Fortunately, for most questions the number of respondents who refused to answer is small. I'll replace the numeric codes 8, 9, and 0 with \passthrough{\lstinline!NaN!}, which is a special value used to indicate missing data. \begin{lstlisting}[language=Python,style=source] clean = column.replace([0, 8, 9], np.nan) \end{lstlisting} We can use \passthrough{\lstinline!notna!} and \passthrough{\lstinline!sum!} to count the valid responses: \begin{lstlisting}[language=Python,style=source] clean.notna().sum() \end{lstlisting} \begin{lstlisting}[style=output] 55328 \end{lstlisting} And we use \passthrough{\lstinline!isna!} to count the missing responses: \begin{lstlisting}[language=Python,style=source] clean.isna().sum() \end{lstlisting} \begin{lstlisting}[style=output] 9486 \end{lstlisting} We can \href{https://gssdataexplorer.norc.org/projects/52787/variables/178/vshow}{check these results against the codebook}; at the bottom of that page, it reports the number of ``Valid cases'' and ``Missing cases''. However, in this example, the results don't match. The codebook reports 53081 valid cases and 9385 missing cases. To figure out what was wrong, I looked at the difference between the values in the codebook and the values I computed from the dataset. \begin{lstlisting}[language=Python,style=source] clean.notna().sum() - 53081 \end{lstlisting} \begin{lstlisting}[style=output] 2247 \end{lstlisting} \begin{lstlisting}[language=Python,style=source] clean.isna().sum() - 9385 \end{lstlisting} \begin{lstlisting}[style=output] 101 \end{lstlisting} That looks like about one year of data, so I guessed that the numbers in the code book might not include the most recent data, from 2018. Here are the numbers from 2018. \begin{lstlisting}[language=Python,style=source] one_year = (gss['year'] == 2018) one_year.sum() \end{lstlisting} \begin{lstlisting}[style=output] 2348 \end{lstlisting} \begin{lstlisting}[language=Python,style=source] clean[one_year].notna().sum() \end{lstlisting} \begin{lstlisting}[style=output] 2247 \end{lstlisting} \begin{lstlisting}[language=Python,style=source] clean[one_year].isna().sum() \end{lstlisting} \begin{lstlisting}[style=output] 101 \end{lstlisting} It looks like my hypothesis is correct; the summary statistics in the codebook do not include data from 2018. Based on these checks, it looks like the dataset is intact and we have loaded it correctly. \hypertarget{replacing-missing-data}{% \section{Replacing missing data}\label{replacing-missing-data}} For the other variables in this dataset, I read through the code book and identified the special values that indicate missing data. I recorded that information in the following function, which is intended to replace special values with \passthrough{\lstinline!NaN!}. \begin{lstlisting}[language=Python,style=source] def replace_invalid(df, columns, bad): for column in columns: df[column].replace(bad, np.nan, inplace=True) def gss_replace_invalid(df): """Replace invalid data with NaN. df: DataFrame """ # different variables use different codes for invalid data df.cohort.replace([0, 9999], np.nan, inplace=True) df.marcohrt.replace([0, 9999], np.nan, inplace=True) # since there are a lot of variables that use 0, 8, and 9 for invalid data, # I'll use a loop to replace all of them columns = ['abany', 'abdefect', 'abhlth', 'abnomore', 'abpoor', 'abrape', 'absingle', 'affrmact', 'bible', 'cappun', 'colath', 'colcom', 'colhomo', 'colmil', 'colmslm', 'colrac', 'compuse', 'conarmy', 'conbus', 'conclerg', 'coneduc', 'confed', 'confinan', 'conjudge', 'conlabor', 'conlegis', 'conmedic', 'conpress', 'consci', 'contv', 'databank', 'discaffm', 'discaffw', 'divlaw', 'divorce', 'fair', 'fear', 'fechld', 'fefam', 'fehire', 'fejobaff', 'fepol', 'fepresch', 'finrela', 'fund', 'fund16', 'god', 'grass', 'gunlaw', 'hapmar', 'happy', 'health', 'helpful', 'homosex', 'hunt', 'letdie1', 'libath', 'libcom', 'libhomo', 'libmil', 'libmslm', 'librac', 'life', 'memchurh', 'meovrwrk', 'nataid', 'natarms', 'natchld', 'natcity', 'natcrime', 'natcrimy', 'natdrug', 'nateduc', 'natenrgy', 'natenvir', 'natfare', 'natheal', 'natmass', 'natpark', 'natrace', 'natroad', 'natsci', 'natsoc', 'natspac', 'polviews', 'pornlaw', 'postlife', 'pray', 'prayer', 'premarsx', 'pres04', 'pres08', 'pres12', 'racmar', 'racopen', 'racpres', 'reborn', 'relexp', 'reliten', 'relpersn', 'res16', 'satfin', 'satjob', 'savesoul', 'sexeduc', 'spanking', 'spkath', 'spkcom', 'spkhomo', 'spkmil', 'spkmslm', 'spkrac', 'sprel16', 'sprtprsn', 'teensex', 'trust', 'union_', 'xmarsex'] replace_invalid(df, columns, [0, 8, 9]) columns = ['degree', 'padeg', 'madeg', 'spdeg', 'partyid'] replace_invalid(df, columns, [8, 9]) df.phone.replace([0, 2, 9], np.nan, inplace=True) df.owngun.replace([0, 3, 8, 9], np.nan, inplace=True) df.pistol.replace([0, 3, 8, 9], np.nan, inplace=True) df.class_.replace([0, 5, 8, 9], np.nan, inplace=True) df.chldidel.replace([-1, 8, 9], np.nan, inplace=True) df.attend.replace([9], np.nan, inplace=True) df.childs.replace([9], np.nan, inplace=True) df.adults.replace([9], np.nan, inplace=True) df.relactiv.replace([0, 98, 89], np.nan, inplace=True) df.age.replace([0, 98, 99], np.nan, inplace=True) df.agewed.replace([0, 98, 99], np.nan, inplace=True) df.relig.replace([0, 98, 99], np.nan, inplace=True) df.relig16.replace([0, 98, 99], np.nan, inplace=True) df.realinc.replace([0], np.nan, inplace=True) df.realrinc.replace([0], np.nan, inplace=True) # note: sibs contains some unlikely numbers df.sibs.replace([-1, 98, 99], np.nan, inplace=True) df.educ.replace([97, 98, 99], np.nan, inplace=True) df.maeduc.replace([97, 98, 99], np.nan, inplace=True) df.paeduc.replace([97, 98, 99], np.nan, inplace=True) df.speduc.replace([97, 98, 99], np.nan, inplace=True) df.income.replace([0, 13, 98, 99], np.nan, inplace=True) df.rincome.replace([0, 13, 98, 99], np.nan, inplace=True) \end{lstlisting} \begin{lstlisting}[language=Python,style=source] gss_replace_invalid(gss) \end{lstlisting} \begin{lstlisting}[language=Python,style=source] # try to make the dataset smaller by replacing # 64-bit FP numbers with 32-bit. for varname in gss.columns: if gss[varname].dtype == np.float64: gss[varname] = gss[varname].astype(np.float32) \end{lstlisting} At this point, I have only moderate confidence that this code is correct. I'm not sure I have dealt with every variable in the dataset, and I'm not sure that the special values for every variable are correct. So I will ask for your help. \textbf{Exercise}: In order to validate the other variables, I'd like each person who works with this notebook to validate one variable. If you run the following cell, it will choose one of the columns from the dataset at random. That's the variable you will check. If you get \passthrough{\lstinline!year!} or \passthrough{\lstinline!id\_!}, run the cell again to get a different variable name. \begin{lstlisting}[language=Python,style=source] np.random.seed(None) np.random.choice(gss.columns) \end{lstlisting} \begin{lstlisting}[style=output] 'natenrgy' \end{lstlisting} Go back through the previous two sections of this notebook and replace \passthrough{\lstinline!polviews!} with your randomly chosen variable. Then run the cells again and go to \href{https://forms.gle/tmST8YCu4qLc414F7}{this online survey to report the results}. Note: Not all questions were asked during all years. If your variable doesn't have data for 1974 or 2018, you might have to choose different years. \hypertarget{resampling}{% \section{Resampling}\label{resampling}} The GSS uses stratified sampling, which means that some groups are deliberately oversampled to help with statistical validity. As a result, each respondent has a sampling weight which is proportional to the number of people in the population they represent. Before running any analysis, we can compensate for stratified sampling by ``resampling'', that is, by drawing a random sample from the dataset, where each respondent's chance of appearing in the sample is proportional to their sampling weight. \begin{lstlisting}[language=Python,style=source] def resample_rows_weighted(df, column): """Resamples a DataFrame using probabilities proportional to given column. df: DataFrame column: string column name to use as weights returns: DataFrame """ weights = df[column] sample = df.sample(n=len(df), replace=True, weights=weights) return sample \end{lstlisting} \begin{lstlisting}[language=Python,style=source] def resample_by_year(df, column): """Resample rows within each year. df: DataFrame column: string name of weight variable returns DataFrame """ grouped = df.groupby('year') samples = [resample_rows_weighted(group, column) for _, group in grouped] sample = pd.concat(samples, ignore_index=True) return sample \end{lstlisting} \begin{lstlisting}[language=Python,style=source] np.random.seed(19) sample = resample_by_year(gss, 'wtssall') \end{lstlisting} \hypertarget{saving-the-results}{% \section{Saving the results}\label{saving-the-results}} I'll save the results to an HDF5 file, which is a binary format that makes it much faster to read the data back. First I'll save the original (not resampled) data. An HDF5 file is like a dictionary on disk. It contains keys and corresponding values. \passthrough{\lstinline!to\_hdf!} takes three arguments: \begin{itemize} \item The filename, \passthrough{\lstinline!gss\_eda.hdf5!}. \item The key, \passthrough{\lstinline!gss!} \item The compression level, which controls how hard the algorithm works to compress the file. \end{itemize} So this file contains a single key, \passthrough{\lstinline!gss!}, which maps to the DataFrame with the original GSS data. The argument \passthrough{\lstinline!w!} says that if the file already exists, we should overwrite it. With compression level \passthrough{\lstinline!3!}, it reduces the size of the file by a factor of 10. \begin{lstlisting}[language=Python,style=source] # save the original gss.to_hdf('gss_eda.hdf5', 'gss', 'w', complevel=3) \end{lstlisting} \begin{lstlisting}[language=Python,style=source] !ls -l gss_eda.hdf5 \end{lstlisting} \begin{lstlisting}[style=output] -rw-rw-r-- 1 downey downey 6939805 May 6 10:24 gss_eda.hdf5 \end{lstlisting} And I'll create a second file with three random resamplings of the original dataset. \begin{lstlisting}[language=Python,style=source] # if the file already exists, remove it import os if os.path.isfile('gss_eda.3.hdf5'): !rm gss_eda.3.hdf5 \end{lstlisting} This file contains three keys, \passthrough{\lstinline!gss0!}, \passthrough{\lstinline!gss1!}, and \passthrough{\lstinline!gss2!}, which map to three DataFrames. \begin{lstlisting}[language=Python,style=source] # generate and store three resamplings keys = ['gss0', 'gss1', 'gss2'] for i in range(3): np.random.seed(i) sample = resample_by_year(gss, 'wtssall') sample.to_hdf('gss_eda.3.hdf5', keys[i], complevel=3) \end{lstlisting} \begin{lstlisting}[language=Python,style=source] !ls -l gss_eda.3.hdf5 \end{lstlisting} \begin{lstlisting}[style=output] -rw-rw-r-- 1 downey downey 20717248 May 6 10:24 gss_eda.3.hdf5 \end{lstlisting} For the other notebooks in this case study, we'll load this resampled data rather than reading and cleaning the data every time.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % MINUIT User Guide -- LaTeX Source % % % % Chapter 2 % % % % The following external EPS files are referenced: % % % % Editor: Michel Goossens / CN-AS % % Last Mod.: 1 Apr. 1992 10:10 mg % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \chapter{Minuit Installation.} \section{Minuit Releases.} Minuit has been extensively revised in 1989, but the usage is largely compatible with that of older versions which have been in use since before 1970. Users familiar with older releases, who have not yet used releases from 1989 or later, must however read this manual, in order to adapt to the few changes as well as to discover the new features and easier ways of using old features, such as free-field input. \section{Minuit Versions.} The program is entirely in standard portable Fortran 77, and requires no external subroutines except those defined as part of the Fortran 77 standard and one logical function \Rind{INTRAC} \footnote{\texttt{INTRAC} is available from the CERN Program Library for all common computers, and in the worst case can be replaced by a \texttt{LOGICAL FUNCTION} returning a value of \texttt{.TRUE.} or \texttt{.FALSE.} depending on whether or not Minuit is being used interactively.}. The only difference between versions for different computers, apart from \Rind{INTRAC}, is the floating point precision (see heading below). As with previous releases, Minuit does not use a memory manager. This makes it easy to install and independent of other programs, but has the disadvantage that both the memory occupation and the maximum problem size (number of parameters) are fixed at compilation time. The old solution to this problem, which consisted of providing ``long'' and ``short'' versions, has proved to be somewhat clumsy and anyway insufficient for really exceptional users, so it has been abandoned in favour of a single ``standard'' version. \index{parameters!number of} \index{version} \index{variable} The currently``standard'' version of Minuit will handle functions of up to 100 parameters, of which not more than 50 can be variable at one time. Because of the use of the \texttt{PARAMETER} statement in the Fortran source, redimensioning for larger (or smaller) versions is very easy (although it will help to have a source code manager or a good editor to propagate the modified \texttt{PARAMETER} statement through all the subroutines, and of course it implies recompilation). The definition of what is ``standard'' may well change in the light of experience (it was 35 instead of 50 variable parameters for release 89.05), and it is likely that different installations will wish to define it differently according to their own applications. In any case, the dimensions used at compilation time are printed in the program header at execution time, and the program is of course protected against the user trying to define too many parameters. The user who finds that the version available to him is too small (or too big) must try to convince his computer manager to change the installation default or to provide an additional special version, or else he must obtain the source and recompile his own version. \section{Interference with Other Packages} The new Minuit has been designed to interfere as little as possible with other programs or packages which may be loaded at the same time. Thus it uses no memory manager or other external subroutines (except \texttt{LOGICAL FUNCTION INTRAC}), all its own subroutine names start with the letters \texttt{MN} (except Minuit and the user written routines), all \texttt{COMMON} block names start with the characters \texttt{MN7}, and the user should not need to use explicitly any Minuit \texttt{COMMON} blocks. In addition, more than one different functions can be minimized in the same execution module, provided the functions have different names, and provided one minimization and error analysis is completely finished before the next one begins. \section{Floating-point Precision} It is recommended for most applications to use 64-bit floating point precision, or the nearest equivalent on any particular machine. This means that the standard Minuit installed on Vax, IBM and Unix workstations will normally be the \texttt{DOUBLE PRECISION} version, while on CDC and Cray it will be \texttt{SINGLE PRECISION}. The arguments of the user's \Rind{FCN} must of course correspond in type to the declarations compiled into the Minuit version being used. The same is true of course for all floating-point arguments to any Minuit routines called directly by the user in Fortran-callable mode. Furthermore, Minuit detects at execution time the precision with which it was compiled, and expects that the calculations inside \Rind{FCN} will be performed approximately to the same accuracy. (This accuracy is called \texttt{EPSMAC} and is printed in the header produced by Minuit when it begins execution.) If the user fools Minuit by using a double precision version but making internal \Rind{FCN} or \Rind{FUTIL} computations in single precision, Minuit will interpret roundoff noise as significant and will usually either fail to find a minimum, or give incorrect values for the parameter errors. It is therefore recommended, when using double precision (\texttt{REAL*8}) Minuit, to make sure all computations in \Rind{FCN} and \Rind{FUTIL} (if used), as well as all subroutines called by \Rind{FCN} and \Rind{FUTIL}, are \texttt{REAL*8}, by including the appropriate \texttt{IMPLICIT} declarations in \Rind{FCN} and all user subroutines called by \Rind{FCN}. If for some reason the computations cannot be done to a precision comparable with that expected by Minuit, the user {\bf must} inform Minuit of this situation with the \Cind[SET EPSmachine]{SET EPS} command. Although 64-bit precision is recommended in general, the new Minuit is so careful to use all available precision that in many cases, 32 bits will in fact be enough. It is therefore possible now to envisage in some situations (for example on microcomputers or when memory is severely limited, or if 64-bit arithmetic is very slow) the use of Minuit with 32- or 36-bit precision. With reduced precision, the user may find that certain features sensitive to first and second differences (\Cind{HESse}, \Cind{MINOs}, \Cind{MNContour}) do not work properly, in which case the calculations must be performed in higher precision.
\section{Introduction} OptimTraj is a matlab library designed for solving continuous-time single-phase trajectory optimization problems. I developed it while working on my PhD at Cornell, studying non-linear controller design for walking robots. \subsection{What sort of problems does OptimTraj solve?} \subsubsection*{Examples:} \begin{itemize} \item Cart-Pole Swing-Up: Find the force profile to apply to the cart to swing-up the pendulum that freely hangs from it. \item Compute the gait (joint angles, rates, and torques) for a walking robot that minimizes the energy used while walking. \item Find a minimum-thrust orbit transfer trajectory for a satellite. \end{itemize} \subsubsection*{Details:} OptimTraj finds the optimal trajectory for a dynamical system. This trajectory is a sequence of controls (expressed as a function) that moves the dynamical system between two points in state space. The trajectory will minimize some cost function, which is typically an integral along the trajectory. The trajectory will also satisfy a set user-defined constraints. All functions in the problem description can be non-linear, but they must be smooth (C$^2$ continuous). OptimTraj solves problems with \begin{itemize} \setlength\itemsep{-0.1em} \item continuous dynamics \item boundary constraints \item path constraints \item integral cost function \item boundary cost function \end{itemize} \subsection{Features:} \begin{itemize} \setlength\itemsep{-0.1em} \item {\bf Easy to Install: } no dependencies outside of Matlab \footnotemark \item {\bf Lots of example: } look at the \texttt{deom/} directory to see for yourself! \item {\bf Readable source code: } easy to debug your code and figure out how the software works \item {\bf Analytic gradients: } most methods support analytic gradients \item {\bf Rapidly switch between methods: } helpful for debugging and experimenting \begin{itemize} \setlength\itemsep{-0.1em} \item Trapezoidal Direct Collocation \item Hermite-Simpson Direct Collocation \item Runge--Kutta $4^\text{th}$-order Multiple Shooting \item Chebyshev--Lobatto Orthogonal Collocation \end{itemize} \end{itemize} \footnotetext{Chebyshev--Lobatto method requires ChebFun (\texttt{http://www.chebfun.org})} \subsection{Installation:} \begin{enumerate} \setlength\itemsep{-0.1em} \item Clone or download the repository (\texttt{https://github.com/MatthewPeterKelly/OptimTraj}) \item Add the top level folder to your Matlab path \item (Optional) Clone or download ChebFun (\texttt{http://www.chebfun.org}) to use the Chebyshev--Lobatto method \end{enumerate} \subsection{Usage: } \begin{itemize} \setlength\itemsep{-0.1em} \item Call the function \texttt{optimTraj} from inside matlab. \item \texttt{optimTraj} takes a single argument: a struct that describes your trajectory optimization problem. \item \texttt{optimTraj} returns a struct that describes the solution. It contains a full description of the problem, the transcription method that was used, and the solution (both as a vector of points and a function handle for interpolation). \item For more details, type \texttt{>> help optimTraj} at the command line, or check out some of the examples in the \texttt{demo/} directory. \end{itemize} \subsection{License: } OptimTraj is published under the MIT License, Copyright (c) 2016 Matthew P. Kelly. \vspace{0.5em} \\ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: \vspace{0.5em} \\ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. \vspace{0.5em} \\ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\documentclass[10pt,journal,compsoc]{IEEEtran} \ifCLASSOPTIONcompsoc \usepackage[nocompress]{cite} \else \usepackage{cite} \fi \ifCLASSINFOpdf \usepackage[pdftex]{graphicx} \graphicspath{{./images/}} \DeclareGraphicsExtensions{.pdf,.jpeg,.png} \else \usepackage[dvips]{graphicx} \graphicspath{{./images/}} \DeclareGraphicsExtensions{.eps} \fi \usepackage{amsmath} \interdisplaylinepenalty=2500 \usepackage{url} \hyphenation{op-tical semi-conduc-tor} \begin{document} \title{Authentication in the Internet of Things} \author{Di~Weng,~\IEEEmembership{11621046} and~Qi~Song,~\IEEEmembership{21521081}% <-this % stops a space % \IEEEcompsocitemizethanks{\IEEEcompsocthanksitem M. Shell was with the Department % of Electrical and Computer Engineering, Georgia Institute of Technology, Atlanta, % GA, 30332.\protect\\ % % note need leading \protect in front of \\ to get a newline within \thanks as % % \\ is fragile and will error, could use \hfil\break instead. % E-mail: see http://www.michaelshell.org/contact.html % \IEEEcompsocthanksitem J. Doe and J. Doe are with Anonymous University.}% <-this % stops an unwanted space \thanks{Manuscript received June 28, 2017; revised June 28, 2017.}} \markboth{Advanced Computer Network, Summer 2017}% {Di~Weng \and Qi~Song: Authentication in the Internet of Things} \IEEEtitleabstractindextext{% \begin{abstract} The Internet of Things (IoT) technology has been increasingly popular in the past few years, given the wide applicability in a variety of domains, including transportation, logistics, healthcare, smart environments, etc. However, the massive and distributed nature of Internet of Things also brings severe security issues along the way. Authentication is one of the key technologies in traditional networks to address security and privacy concerns. With the evolution of Internet of Things networks, authentication technologies continue playing a significant role in the application, architecture, and user authentication of Internet of Things. This survey briefly presents the background of Internet of Things, describes the techniques proposed in three aforementioned types of authentication, and concludes the state of research in this area. \end{abstract} % Note that keywords are not normally used for peerreview papers. \begin{IEEEkeywords} internet of things, authentication. \end{IEEEkeywords}} % make the title area \maketitle \IEEEdisplaynontitleabstractindextext \IEEEpeerreviewmaketitle \IEEEraisesectionheading{\section{Introduction}\label{sec:introduction}} \input{texfiles/introduction} \section{Application Authentication\label{sec:application}} \input{texfiles/application} \section{Architecture Authentication\label{sec:architecture}} \input{texfiles/architecture} \section{User Authentication\label{sec:user}} \input{texfiles/user} \section{Conclusion\label{sec:conclusion}} \input{texfiles/conclusion} \newpage \bibliographystyle{abbrv} \bibliography{survey} \end{document}
Our approach to adaptive refinement in \pelelm\ uses a nested hierarchy of logically-rectangular grids with simultaneous refinement of the grids in both space and time. The integration algorithm on the grid hierarchy is a recursive procedure in which coarse grids are advanced in time, fine grids are advanced multiple steps to reach the same time as the coarse grids and the data at different levels are then synchronized. During the regridding step, increasingly finer grids are recursively embedded in coarse grids until the solution is sufficiently resolved. An error estimation procedure based on user-specified criteria (described in Section \ref{sec:tagging}) evaluates where additional refinement is needed and grid generation procedures dynamically create or remove rectangular fine grid patches as resolution requirements change. A good introduction to the style of AMR used here is in Lecture 1 of the Adaptive Mesh Refinement Short Course at https://ccse.lbl.gov/people/jbb/index.html \section{Tagging for Refinement} \label{sec:tagging} \pelelm\ determines what zones should be tagged for refinement at the next regridding step by using a set of built-in routines that test on quantities such as the density and pressure and determining whether the quantities themselves or their gradients pass a user-specified threshold. This may then be extended if {\tt amr.n\_error\_buf} $> 0$ to a certain number of zones beyond these tagged zones. This section describes the process by which zones are tagged, and describes how to add customized tagging criteria. The routines for tagging cells are located in the {\tt Prob\_nd.f90} file in the {\tt Src\_nd} directory. The main routines are {\tt denerror}, {\tt temperror}, {\tt presserror}, {\tt velerror}. They refine based on density, temperature, pressure, and velocity, respectively. The same approach is used for all of them. As an example, we consider the density tagging routine. There are four parameters that control tagging. If the density in a zone is greater than the user-specified parameter {\tt denerr}, then that zone will be tagged for refinement, but only if the current AMR level is less than the user-specified parameter {\tt max\_denerr\_lev}. Similarly, if the absolute density gradient between a zone and any adjacent zone is greater than the user-specified parameter {\tt dengrad}, that zone will be tagged for refinement, but only if we are currently on a level below {\tt max\_dengrad\_lev}. Note that setting {\tt denerr} alone will not do anything; you'll need to set {\tt max\_dengrad\_lev} $>= 1$ for this to have any effect. All four of these parameters are set in the {\tt \&tagging} namelist in your {\tt probin} file. If left unmodified, they default to a value that means we will never tag. The complete set of parameters that can be controlled this way is the following: \begin{multicols}{5} \begin{itemize} \setlength{\itemindent}{-3em} \item {\tt denerr} \item {\tt max\_denerr\_lev} \item {\tt dengrad} \item {\tt max\_dengrad\_lev} \item {\tt temperr} \item {\tt max\_temperr\_lev} \item {\tt tempgrad} \item {\tt max\_tempgrad\_lev} \item {\tt velerr} \item {\tt max\_velerr\_lev} \item {\tt velgrad} \item {\tt max\_velgrad\_lev} \item {\tt presserr} \item {\tt max\_presserr\_lev} \item {\tt pressgrad} \item {\tt max\_pressgrad\_lev} \item {\tt raderr} \item {\tt max\_raderr\_lev} \item {\tt radgrad} \item {\tt max\_radgrad\_lev} \end{itemize} \end{multicols} Since there are multiple algorithms for determining whether a zone is tagged or not, it is worthwhile to specify in detail what is happening to a zone in the code during this step. We show this in the following pseudocode section. A zone is tagged if the variable {\tt itag = SET}, and is not tagged if {\tt itag = CLEAR} (these are mapped to 1 and 0, respectively). \begin{verbatim} itag = CLEAR for errfunc[k] from k = 1 ... N // Three possibilities for itag: SET or CLEAR or remaining unchanged call errfunc[k](itag) end for \end{verbatim} In particular, notice that there is an order dependence of this operation; if {\tt errfunc[2]} {\tt CLEAR}s a zone and then {\tt errfunc[3]} {\tt SET}s that zone, the final operation will be to tag that zone (and vice versa). In practice by default this does not matter, because the built-in tagging routines never explicitly perform a \texttt{CLEAR}. However, it is possible to overwrite the {\tt Tagging\_nd.f90} file if you want to change how {\tt ca\_denerror, ca\_temperror}, etc. operate. This is not recommended, and if you do so be aware that {\tt CLEAR}ing a zone this way may not have the desired effect. We provide also the ability for the user to define their own tagging criteria. This is done through the Fortran function {\tt set\_problem\_tags} in the {\tt problem\_tagging\_*d.f90} files. This function is provided the entire state (including density, temperature, velocity, etc.) and the array of tagging status for every zone. As an example of how to use this, suppose we have a 3D Cartesian simulation where we want to tag any zone that has a density gradient greater than 10, but we don't care about any regions outside a radius $r > 75$ from the problem origin; we leave them always unrefined. We also want to ensure that the region $r \leq 10$ is always refined. In our {\tt probin} file we would set {\tt denerr = 10} and {\tt max\_denerr\_lev = 1} in the {\tt \&tagging} namelist. We would also make a copy of {\tt problem\_tagging\_3d.f90} to our work directory and set it up as follows: \clearpage \begin{verbatim} subroutine set_problem_tags(tag,tagl1,tagl2,tagl3,tagh1,tagh2,tagh3, & state,state_l1,state_l2,state_l3,state_h1,state_h2,state_h3,& set,clear,& lo,hi,& dx,problo,time,level) use bl_constants_module, only: ZERO, HALF use prob_params_module, only: center use meth_params_module, only: URHO, UMX, UMY, UMZ, UEDEN, NVAR implicit none integer ,intent(in ) :: lo(3),hi(3) integer ,intent(in ) :: state_l1,state_l2,state_l3, & state_h1,state_h2,state_h3 integer ,intent(in ) :: tagl1,tagl2,tagl3,tagh1,tagh2,tagh3 double precision,intent(in ) :: state(state_l1:state_h1, & state_l2:state_h2, & state_l3:state_h3,NVAR) integer ,intent(inout) :: tag(tagl1:tagh1,tagl2:tagh2,tagl3:tagh3) double precision,intent(in ) :: problo(3),dx(3),time integer ,intent(in ) :: level,set,clear double precision :: x, y, z, r do k = lo(3), hi(3) z = problo(3) + (dble(k) + HALF) * dx(3) - center(3) do j = lo(2), hi(2) y = problo(2) + (dble(j) + HALF) * dx(2) - center(2) do i = lo(1), hi(1) x = problo(1) + (dble(i) + HALF) * dx(1) - center(2) r = (x**2 + y**2 + z**2)**(HALF) if (r > 75.0) then tag(i,j,k) = clear elseif (r <= 10.0) then tag(i,j,k) = set endif enddo enddo enddo end subroutine set_problem_tags \end{verbatim}
\documentclass[revision-guide.tex]{subfiles} %% Current Author: PS \setcounter{chapter}{17} \begin{document} \chapter{The Quantum Atom} \begin{content} \item linespectra \item energy levels in the hydrogen atom \end{content} \section*{Candidates should be able to:} \spec{explain atomic line spectra in terms of photon emission and transitions between discrete energy levels} When a gas of atoms is given energy (e.g. by an electric field) that energy is emitted at electromagnetic waves at a few, specific frequencies. These frequencies are the same for every atom of a specific element; however they differ between elements. At typical line spectrum is shown in Figure %TODO. The explanation for this behaviour is the quantisation of energy levels within the atom. Electrons are only able have occupy certain (discrete) energies and when they move between these energies they emit (or absorb) photons of electromagnetic radiation. These photons have different frequencies depending on the amount of energy they carry away. \spec{apply $E = hf$ to radiation emitted in a transition between energy levels} When an electron in an atom falls from one energy level to a lower one the excess energy is emitted as a photon. The energy of this photon is equal to the energy lost. \begin{example} An electron in an atom falls from the $n=3$ state to the $n=2$ state as shown below. Calculate the wavelength of the photon emitted. \begin{center} \begin{tikzpicture} \draw[thick, ->] (0,-5) -- (0,0) node[anchor=east] {$E / \si{\electronvolt}$}; \draw (0,-4.5) node[anchor=east] {\SI{-23.5}{\electronvolt}} -- (3,-4.5) node[anchor=west] {$n=1$}; \draw (0,-1.125) node[anchor=east] {\SI{-5.88}{\electronvolt}} -- (3,-1.125) node[anchor=west] {$n=2$}; \draw (0,-0.5) node[anchor=east] {\SI{-2.61}{\electronvolt}} -- (3,-.5) node[anchor=west] {$n=3$}; \draw[bend right, very thick, ->] (2,-.5) .. controls (2.1,-0.812) .. (2,-1.125); \draw[decorate, decoration={coil, aspect=0}, ->] (2.1, -0.812) -- (5,-0.812) node[anchor=south]{$\gamma$}; \end{tikzpicture} \end{center} \answer The difference in energy between the two levels is given by \[ E = \left(\SI{-2.61}{\electronvolt}\right) - \left(\SI{-5.88}{\electronvolt}\right) = \SI{3.27}{\electronvolt} \] The wavelength can be calculated using \[ E = hf = \frac{hc}{\lambda} \] \[ \lambda = \frac{hc}{E} = \frac{hc}{\SI{5.24e-19}{\joule}} = \SI{379}{\nano\meter} \] \end{example} \spec{show an understanding of the hydrogen line spectrum, photons and energy levels as represented by the Lyman, Balmer and Paschen series} The example above shows a single transition between energy levels. In reality when an atom is excited it will emit photons corresponding to many transitions at once. The example of the Hydrogen atom is shown in Figure \ref{fig:hspec}. These transitions can be grouped into series based on which energy level the electron ends up in. Here there are three series shown which correspond to the Lyman (falling to $n=1$), Balmer (falling to $n=2$) and Paschen (falling to $n=3$) Series. For simplicity only six energy levels are shown but in reality each series has potentially infinitely many possible starting states, although most of them will have very similar energies (as the starting energy approaches zero). \begin{figure} \begin{center} \begin{tikzpicture} \draw[thick, ->] (0,-5.5 cm) -- (0,1) node[anchor=east] {$E / \si{\electronvolt}$}; \foreach \n/\y in {1/-5,2/-3,3/-1.5,4/-.8,5/-.3,6/0}{ \draw[thick] (0cm,\y) -- (7cm,\y) node[anchor=west]{$n=\n$}; } \foreach \x/\y in {.5/-3,.7/-1.5,.9/-.8,1.1/-.3,1.3/0} { \draw[-{Latex}] (\x,\y) -- (\x,-5); } \foreach \x/\y in {2.5/-1.5,2.7/-.8,2.9/-.3,3.1/0} { \draw[-{Latex}] (\x,\y) -- (\x,-3); } \foreach \x/\y in {3.7/-.8,3.9/-.3,4.1/0} { \draw[-{Latex}] (\x,\y) -- (\x,-1.5); } \draw[thick,dashed] (0cm,.3) node[anchor=east]{0} -- (7cm,.3) node[anchor=west] {$n=\infty$}; \draw (1.5,-4) node[anchor=west]{\emph{Lyman Series (UV)}}; \draw (3.5,-2.25) node[anchor=west]{\emph{Balmer Series (Visible)}}; \draw (4.5, -1.15) node[anchor=west]{\emph{Paschen Series (IR)}}; \end{tikzpicture} \end{center} \caption{Transitions corresponding to the Hydrogen spectrum} \label{fig:hspec} \end{figure} \spec{recognise and use the energy levels of the hydrogen atom as described by the empirical equation \begin{equation}\label{eqn:hlevels} E_n = \frac{\SI{-13.6}{\electronvolt}}{n^2}% \end{equation}} By studying the line spectra of hydrogen equation \ref{eqn:hlevels} can be determined from experiment. The equation can be used to determine the wavelengths of the emission lines of the Hydrogen spectrum: \[ E_\gamma = \SI{-13.6}{\electronvolt}\left(\frac{1}{n_2^2}-\frac{1}{n_1^2}\right) \] \spec{*explain energy levels using the model of standing waves in a rectangular one-dimensional potential well} The orbital model of electrons in an atom allows electrons to have any energy we require. However, if one considers the electron to be acting as a standing wave then the idea of discrete energy levels comes naturally. The simplest model of an electron as a standing wave is to consider the standing wave as a linear wave bound at each end. With an electron we define a `potential well', i.e. a region of space in which the electron has zero potential energy and the rest of space the electron would have infinite potential energy. The electron is therefore bound within this space. \begin{figure} \begin{center} \begin{tikzpicture}[domain=0:6] \draw[-{Latex},thick] (0,-1.5) -- (0,6); \draw[-{Latex},thick] (6,-1.5) -- (6,6); \draw[red] plot (\x, {.5*sin(360*\x/12)}) node[anchor=west]{$n=1$}; \draw[red,dashed] plot (\x, {-.5*sin(360*\x/12)}); \draw[green] plot (\x, {2+.5*sin(360*\x/6)})node[anchor=west]{$n=2$}; \draw[green,dashed] plot (\x, {2-.5*sin(360*\x/6)}); \draw[blue] plot (\x, {4+.5*sin(360*\x/4)})node[anchor=west]{$n=3$}; \draw[blue,dashed] plot (\x, {4-.5*sin(360*\x/4)}); \draw[thick,<->] (0,-1) -- (6,-1) node[midway, anchor=north]{$L$}; \end{tikzpicture} \end{center} \caption{Three standing waves in a potential well} \label{fig:potwell} \end{figure} For each of the standing waves described in Figure \ref{fig:potwell} the wavelength can be calculated using \begin{equation} \lambda_n = \frac{2L}{n} \end{equation} If the wavelength is related to the de Broglie wavelength of the electron then each of these standing waves can be given an momentum and hence energy. \begin{equation}\label{eqn:potwell} E_n = \frac{p^2}{2m} = \frac{h^2}{2m\lambda^2} = \frac{h^2n^2}{8mL^2} \end{equation} Equation \ref{eqn:potwell} clearly can not match the empirical equation (\ref{eqn:hlevels}), but it does show a dependence on $n$ and discrete energy levels. \spec{*derive the hydrogen atom energy level equation $E_n = \frac{\SI{-13.6}{\electronvolt}}{n^2}$ algebraically using the model of electron standing waves, the de Broglie relation and the quantisation of angular momentum. } In order to adapt the above model to fit an atom, the idea of the potential well was adapted to say that instead of fitting inside a potential well, a whole number of wavelengths should fit around the circumference of the atom. This gives a new criterion: \begin{equation}\label{eqn:2pir} 2\pi r = n\lambda \end{equation} The de Broglie wavelength equation can be substituted into equation \ref{eqn:2pir} to give \begin{equation}\label{eqn:quanL} mvr = \frac{nh}{2\pi} \end{equation} The quantity on the left is the \emph{angular momentum}. It turns out that our quantisation rule based on wavelength is equivalent to stating that the angular momentum is quantised. The value $\frac{h}{2\pi}$ is so common in quantum theory that it has its own symbol, $\hbar$. In fact, equation \ref{eqn:quanL} was Bohr's starting point for his model of the atom. Now we have a rule for the quantisation we can apply it to the classical model of the hydrogen atom. The electron in the classical model has electrostatic potential energy due to its attraction to the nucleus and kinetic energy due to its orbit around the nucleus. In order to calculate the kinetic energy we calculate the $v^2$ by equating the centripetal force to the electrostatic attraction. \begin{align} \frac{mv^2}{r} &= \frac{e^2}{4\pi\epsilon_0 r^2} \nonumber \\ v^2 &= \frac{e^2}{4m\pi\epsilon_0 r}\label{eqn:v2} \end{align} Note that we use this expression for $v^2$ \emph{twice} in our derivation. Energy can now be calculated: \begin{align} E &= \text{KE} + \text{PE}\nonumber \\ &= \frac{1}{2}mv^2 + -\frac{e^2}{4\pi\epsilon_0 r}\label{eqn:e1}\\ &= \frac{e^2}{8\pi\epsilon_0 r} - \frac{e^2}{4\pi\epsilon_0 r} \nonumber \\ &= -\frac{e^2}{8\pi\epsilon_0 r}\label{eqn:e} \end{align} Note that in equation \ref{eqn:e1} the PE is negative due to the opposite signs of the electron and the nucleus and that the total energy (\ref{eqn:e}) is negative due to the bound state of the electron. We can now introduce our quantisation criteria (\ref{eqn:quanL}) by calculating the allowed values of $r$. This makes use of the $v^2$ term from equation \ref{eqn:v2}. The difficult point is to remember that equation \ref{eqn:quanL} should be rearranged to give $r$ \emph{squared}. \begin{align} r^2 &= \frac{n^2 h^2}{4\pi^2 m^2 v^2}\\ &= \frac{n^2 h^2}{4\pi^2 m^2} \frac{4m\pi\epsilon_0 r}{e^2}\\ r &= \frac{n^2h^2\epsilon_0}{\pi m e^2} \label{eqn:quanr} \end{align} Finally, equation (\ref{eqn:quanr}) is substituted into the equation for energy (\ref{eqn:e}) \begin{align*} E &= -\frac{e^2}{8\pi\epsilon_0 r}\\ &= -\frac{e^2}{8\pi\epsilon_0} \frac{\pi m e^2}{n^2h^2\epsilon_0} \\ &= - \frac{me^4}{8\epsilon_0^2 n^2 h^2}\\ &= \frac{E_1}{n^2}\\ \end{align*} \[ \text{where } E_1 = -\frac{me^4}{8\epsilon_0^2 h^2} = \SI{-2.17e-18}{\joule} = \SI{-13.6}{\electronvolt} \] which matches the empirical formula (\ref{eqn:hlevels})! \emph{Note that many calculators give a value of zero if you type this equation in as one calculation. This is because $me^4 = \num{5.97e-106}$ which casio calculators cannot cope with. A way around this is to calculate directly in electron-volts by dividing through by $e$ thus requring only $me^3$ to be calculated.} This powerful piece of reasoning also gives a value for the radius of the hydrogen atom which matches that measured by experiment. This reasoning can be extended to nuclei with different charges; however it only works with a single electron as further inter-electron interactions are not taken into account. \end{document}
\documentclass[11pt]{article} \usepackage[breakable]{tcolorbox} \usepackage{parskip} % Stop auto-indenting (to mimic markdown behaviour) \usepackage{iftex} \ifPDFTeX \usepackage[T1]{fontenc} \usepackage{mathpazo} \else \usepackage{fontspec} \fi % Basic figure setup, for now with no caption control since it's done % automatically by Pandoc (which extracts ![](path) syntax from Markdown). \usepackage{graphicx} % Maintain compatibility with old templates. Remove in nbconvert 6.0 \let\Oldincludegraphics\includegraphics % Ensure that by default, figures have no caption (until we provide a % proper Figure object with a Caption API and a way to capture that % in the conversion process - todo). \usepackage{caption} \DeclareCaptionFormat{nocaption}{} \captionsetup{format=nocaption,aboveskip=0pt,belowskip=0pt} \usepackage[Export]{adjustbox} % Used to constrain images to a maximum size \adjustboxset{max size={0.9\linewidth}{0.9\paperheight}} \usepackage{float} \floatplacement{figure}{H} % forces figures to be placed at the correct location \usepackage{xcolor} % Allow colors to be defined \usepackage{enumerate} % Needed for markdown enumerations to work \usepackage{geometry} % Used to adjust the document margins \usepackage{amsmath} % Equations \usepackage{amssymb} % Equations \usepackage{textcomp} % defines textquotesingle % Hack from http://tex.stackexchange.com/a/47451/13684: \AtBeginDocument{% \def\PYZsq{\textquotesingle}% Upright quotes in Pygmentized code } \usepackage{upquote} % Upright quotes for verbatim code \usepackage{eurosym} % defines \euro \usepackage[mathletters]{ucs} % Extended unicode (utf-8) support \usepackage{fancyvrb} % verbatim replacement that allows latex \usepackage{grffile} % extends the file name processing of package graphics % to support a larger range \makeatletter % fix for grffile with XeLaTeX \def\Gread@@xetex#1{% \IfFileExists{"\Gin@base".bb}% {\Gread@eps{\Gin@base.bb}}% {\Gread@@xetex@aux#1}% } \makeatother % The hyperref package gives us a pdf with properly built % internal navigation ('pdf bookmarks' for the table of contents, % internal cross-reference links, web links for URLs, etc.) \usepackage{hyperref} % The default LaTeX title has an obnoxious amount of whitespace. By default, % titling removes some of it. It also provides customization options. \usepackage{titling} \usepackage{longtable} % longtable support required by pandoc >1.10 \usepackage{booktabs} % table support for pandoc > 1.12.2 \usepackage[inline]{enumitem} % IRkernel/repr support (it uses the enumerate* environment) \usepackage[normalem]{ulem} % ulem is needed to support strikethroughs (\sout) % normalem makes italics be italics, not underlines \usepackage{mathrsfs} % Colors for the hyperref package \definecolor{urlcolor}{rgb}{0,.145,.698} \definecolor{linkcolor}{rgb}{.71,0.21,0.01} \definecolor{citecolor}{rgb}{.12,.54,.11} % ANSI colors \definecolor{ansi-black}{HTML}{3E424D} \definecolor{ansi-black-intense}{HTML}{282C36} \definecolor{ansi-red}{HTML}{E75C58} \definecolor{ansi-red-intense}{HTML}{B22B31} \definecolor{ansi-green}{HTML}{00A250} \definecolor{ansi-green-intense}{HTML}{007427} \definecolor{ansi-yellow}{HTML}{DDB62B} \definecolor{ansi-yellow-intense}{HTML}{B27D12} \definecolor{ansi-blue}{HTML}{208FFB} \definecolor{ansi-blue-intense}{HTML}{0065CA} \definecolor{ansi-magenta}{HTML}{D160C4} \definecolor{ansi-magenta-intense}{HTML}{A03196} \definecolor{ansi-cyan}{HTML}{60C6C8} \definecolor{ansi-cyan-intense}{HTML}{258F8F} \definecolor{ansi-white}{HTML}{C5C1B4} \definecolor{ansi-white-intense}{HTML}{A1A6B2} \definecolor{ansi-default-inverse-fg}{HTML}{FFFFFF} \definecolor{ansi-default-inverse-bg}{HTML}{000000} % commands and environments needed by pandoc snippets % extracted from the output of `pandoc -s` \providecommand{\tightlist}{% \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}} \DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}} % Add ',fontsize=\small' for more characters per line \newenvironment{Shaded}{}{} \newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{\textbf{{#1}}}} \newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.56,0.13,0.00}{{#1}}} \newcommand{\DecValTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{{#1}}} \newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{{#1}}} \newcommand{\FloatTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{{#1}}} \newcommand{\CharTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}} \newcommand{\StringTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}} \newcommand{\CommentTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textit{{#1}}}} \newcommand{\OtherTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{{#1}}} \newcommand{\AlertTok}[1]{\textcolor[rgb]{1.00,0.00,0.00}{\textbf{{#1}}}} \newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.02,0.16,0.49}{{#1}}} \newcommand{\RegionMarkerTok}[1]{{#1}} \newcommand{\ErrorTok}[1]{\textcolor[rgb]{1.00,0.00,0.00}{\textbf{{#1}}}} \newcommand{\NormalTok}[1]{{#1}} % Additional commands for more recent versions of Pandoc \newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.53,0.00,0.00}{{#1}}} \newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}} \newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}} \newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.73,0.40,0.53}{{#1}}} \newcommand{\ImportTok}[1]{{#1}} \newcommand{\DocumentationTok}[1]{\textcolor[rgb]{0.73,0.13,0.13}{\textit{{#1}}}} \newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{{#1}}}}} \newcommand{\CommentVarTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{{#1}}}}} \newcommand{\VariableTok}[1]{\textcolor[rgb]{0.10,0.09,0.49}{{#1}}} \newcommand{\ControlFlowTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{\textbf{{#1}}}} \newcommand{\OperatorTok}[1]{\textcolor[rgb]{0.40,0.40,0.40}{{#1}}} \newcommand{\BuiltInTok}[1]{{#1}} \newcommand{\ExtensionTok}[1]{{#1}} \newcommand{\PreprocessorTok}[1]{\textcolor[rgb]{0.74,0.48,0.00}{{#1}}} \newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.49,0.56,0.16}{{#1}}} \newcommand{\InformationTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{{#1}}}}} \newcommand{\WarningTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{{#1}}}}} % Define a nice break command that doesn't care if a line doesn't already % exist. \def\br{\hspace*{\fill} \\* } % Math Jax compatibility definitions \def\gt{>} \def\lt{<} \let\Oldtex\TeX \let\Oldlatex\LaTeX \renewcommand{\TeX}{\textrm{\Oldtex}} \renewcommand{\LaTeX}{\textrm{\Oldlatex}} % Document parameters % Document title \title{ML\_prog1} % Pygments definitions \makeatletter \def\PY@reset{\let\PY@it=\relax \let\PY@bf=\relax% \let\PY@ul=\relax \let\PY@tc=\relax% \let\PY@bc=\relax \let\PY@ff=\relax} \def\PY@tok#1{\csname PY@tok@#1\endcsname} \def\PY@toks#1+{\ifx\relax#1\empty\else% \PY@tok{#1}\expandafter\PY@toks\fi} \def\PY@do#1{\PY@bc{\PY@tc{\PY@ul{% \PY@it{\PY@bf{\PY@ff{#1}}}}}}} \def\PY#1#2{\PY@reset\PY@toks#1+\relax+\PY@do{#2}} \expandafter\def\csname PY@tok@w\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.73,0.73}{##1}}} \expandafter\def\csname PY@tok@c\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}} \expandafter\def\csname PY@tok@cp\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.74,0.48,0.00}{##1}}} \expandafter\def\csname PY@tok@k\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} \expandafter\def\csname PY@tok@kp\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} \expandafter\def\csname PY@tok@kt\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.69,0.00,0.25}{##1}}} \expandafter\def\csname PY@tok@o\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} \expandafter\def\csname PY@tok@ow\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.67,0.13,1.00}{##1}}} \expandafter\def\csname PY@tok@nb\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} \expandafter\def\csname PY@tok@nf\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}} \expandafter\def\csname PY@tok@nc\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}} \expandafter\def\csname PY@tok@nn\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}} \expandafter\def\csname PY@tok@ne\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.82,0.25,0.23}{##1}}} \expandafter\def\csname PY@tok@nv\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} \expandafter\def\csname PY@tok@no\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.53,0.00,0.00}{##1}}} \expandafter\def\csname PY@tok@nl\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.63,0.63,0.00}{##1}}} \expandafter\def\csname PY@tok@ni\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.60,0.60,0.60}{##1}}} \expandafter\def\csname PY@tok@na\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.49,0.56,0.16}{##1}}} \expandafter\def\csname PY@tok@nt\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} \expandafter\def\csname PY@tok@nd\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.67,0.13,1.00}{##1}}} \expandafter\def\csname PY@tok@s\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} \expandafter\def\csname PY@tok@sd\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} \expandafter\def\csname PY@tok@si\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.73,0.40,0.53}{##1}}} \expandafter\def\csname PY@tok@se\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.73,0.40,0.13}{##1}}} \expandafter\def\csname PY@tok@sr\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.40,0.53}{##1}}} \expandafter\def\csname PY@tok@ss\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} \expandafter\def\csname PY@tok@sx\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} \expandafter\def\csname PY@tok@m\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} \expandafter\def\csname PY@tok@gh\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,0.50}{##1}}} \expandafter\def\csname PY@tok@gu\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.50,0.00,0.50}{##1}}} \expandafter\def\csname PY@tok@gd\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.63,0.00,0.00}{##1}}} \expandafter\def\csname PY@tok@gi\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.63,0.00}{##1}}} \expandafter\def\csname PY@tok@gr\endcsname{\def\PY@tc##1{\textcolor[rgb]{1.00,0.00,0.00}{##1}}} \expandafter\def\csname PY@tok@ge\endcsname{\let\PY@it=\textit} \expandafter\def\csname PY@tok@gs\endcsname{\let\PY@bf=\textbf} \expandafter\def\csname PY@tok@gp\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,0.50}{##1}}} \expandafter\def\csname PY@tok@go\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.53,0.53,0.53}{##1}}} \expandafter\def\csname PY@tok@gt\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.27,0.87}{##1}}} \expandafter\def\csname PY@tok@err\endcsname{\def\PY@bc##1{\setlength{\fboxsep}{0pt}\fcolorbox[rgb]{1.00,0.00,0.00}{1,1,1}{\strut ##1}}} \expandafter\def\csname PY@tok@kc\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} \expandafter\def\csname PY@tok@kd\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} \expandafter\def\csname PY@tok@kn\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} \expandafter\def\csname PY@tok@kr\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} \expandafter\def\csname PY@tok@bp\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} \expandafter\def\csname PY@tok@fm\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}} \expandafter\def\csname PY@tok@vc\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} \expandafter\def\csname PY@tok@vg\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} \expandafter\def\csname PY@tok@vi\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} \expandafter\def\csname PY@tok@vm\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} \expandafter\def\csname PY@tok@sa\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} \expandafter\def\csname PY@tok@sb\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} \expandafter\def\csname PY@tok@sc\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} \expandafter\def\csname PY@tok@dl\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} \expandafter\def\csname PY@tok@s2\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} \expandafter\def\csname PY@tok@sh\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} \expandafter\def\csname PY@tok@s1\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} \expandafter\def\csname PY@tok@mb\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} \expandafter\def\csname PY@tok@mf\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} \expandafter\def\csname PY@tok@mh\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} \expandafter\def\csname PY@tok@mi\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} \expandafter\def\csname PY@tok@il\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} \expandafter\def\csname PY@tok@mo\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} \expandafter\def\csname PY@tok@ch\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}} \expandafter\def\csname PY@tok@cm\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}} \expandafter\def\csname PY@tok@cpf\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}} \expandafter\def\csname PY@tok@c1\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}} \expandafter\def\csname PY@tok@cs\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}} \def\PYZbs{\char`\\} \def\PYZus{\char`\_} \def\PYZob{\char`\{} \def\PYZcb{\char`\}} \def\PYZca{\char`\^} \def\PYZam{\char`\&} \def\PYZlt{\char`\<} \def\PYZgt{\char`\>} \def\PYZsh{\char`\#} \def\PYZpc{\char`\%} \def\PYZdl{\char`\$} \def\PYZhy{\char`\-} \def\PYZsq{\char`\'} \def\PYZdq{\char`\"} \def\PYZti{\char`\~} % for compatibility with earlier versions \def\PYZat{@} \def\PYZlb{[} \def\PYZrb{]} \makeatother % For linebreaks inside Verbatim environment from package fancyvrb. \makeatletter \newbox\Wrappedcontinuationbox \newbox\Wrappedvisiblespacebox \newcommand*\Wrappedvisiblespace {\textcolor{red}{\textvisiblespace}} \newcommand*\Wrappedcontinuationsymbol {\textcolor{red}{\llap{\tiny$\m@th\hookrightarrow$}}} \newcommand*\Wrappedcontinuationindent {3ex } \newcommand*\Wrappedafterbreak {\kern\Wrappedcontinuationindent\copy\Wrappedcontinuationbox} % Take advantage of the already applied Pygments mark-up to insert % potential linebreaks for TeX processing. % {, <, #, %, $, ' and ": go to next line. % _, }, ^, &, >, - and ~: stay at end of broken line. % Use of \textquotesingle for straight quote. \newcommand*\Wrappedbreaksatspecials {% \def\PYGZus{\discretionary{\char`\_}{\Wrappedafterbreak}{\char`\_}}% \def\PYGZob{\discretionary{}{\Wrappedafterbreak\char`\{}{\char`\{}}% \def\PYGZcb{\discretionary{\char`\}}{\Wrappedafterbreak}{\char`\}}}% \def\PYGZca{\discretionary{\char`\^}{\Wrappedafterbreak}{\char`\^}}% \def\PYGZam{\discretionary{\char`\&}{\Wrappedafterbreak}{\char`\&}}% \def\PYGZlt{\discretionary{}{\Wrappedafterbreak\char`\<}{\char`\<}}% \def\PYGZgt{\discretionary{\char`\>}{\Wrappedafterbreak}{\char`\>}}% \def\PYGZsh{\discretionary{}{\Wrappedafterbreak\char`\#}{\char`\#}}% \def\PYGZpc{\discretionary{}{\Wrappedafterbreak\char`\%}{\char`\%}}% \def\PYGZdl{\discretionary{}{\Wrappedafterbreak\char`\$}{\char`\$}}% \def\PYGZhy{\discretionary{\char`\-}{\Wrappedafterbreak}{\char`\-}}% \def\PYGZsq{\discretionary{}{\Wrappedafterbreak\textquotesingle}{\textquotesingle}}% \def\PYGZdq{\discretionary{}{\Wrappedafterbreak\char`\"}{\char`\"}}% \def\PYGZti{\discretionary{\char`\~}{\Wrappedafterbreak}{\char`\~}}% } % Some characters . , ; ? ! / are not pygmentized. % This macro makes them "active" and they will insert potential linebreaks \newcommand*\Wrappedbreaksatpunct {% \lccode`\~`\.\lowercase{\def~}{\discretionary{\hbox{\char`\.}}{\Wrappedafterbreak}{\hbox{\char`\.}}}% \lccode`\~`\,\lowercase{\def~}{\discretionary{\hbox{\char`\,}}{\Wrappedafterbreak}{\hbox{\char`\,}}}% \lccode`\~`\;\lowercase{\def~}{\discretionary{\hbox{\char`\;}}{\Wrappedafterbreak}{\hbox{\char`\;}}}% \lccode`\~`\:\lowercase{\def~}{\discretionary{\hbox{\char`\:}}{\Wrappedafterbreak}{\hbox{\char`\:}}}% \lccode`\~`\?\lowercase{\def~}{\discretionary{\hbox{\char`\?}}{\Wrappedafterbreak}{\hbox{\char`\?}}}% \lccode`\~`\!\lowercase{\def~}{\discretionary{\hbox{\char`\!}}{\Wrappedafterbreak}{\hbox{\char`\!}}}% \lccode`\~`\/\lowercase{\def~}{\discretionary{\hbox{\char`\/}}{\Wrappedafterbreak}{\hbox{\char`\/}}}% \catcode`\.\active \catcode`\,\active \catcode`\;\active \catcode`\:\active \catcode`\?\active \catcode`\!\active \catcode`\/\active \lccode`\~`\~ } \makeatother \let\OriginalVerbatim=\Verbatim \makeatletter \renewcommand{\Verbatim}[1][1]{% %\parskip\z@skip \sbox\Wrappedcontinuationbox {\Wrappedcontinuationsymbol}% \sbox\Wrappedvisiblespacebox {\FV@SetupFont\Wrappedvisiblespace}% \def\FancyVerbFormatLine ##1{\hsize\linewidth \vtop{\raggedright\hyphenpenalty\z@\exhyphenpenalty\z@ \doublehyphendemerits\z@\finalhyphendemerits\z@ \strut ##1\strut}% }% % If the linebreak is at a space, the latter will be displayed as visible % space at end of first line, and a continuation symbol starts next line. % Stretch/shrink are however usually zero for typewriter font. \def\FV@Space {% \nobreak\hskip\z@ plus\fontdimen3\font minus\fontdimen4\font \discretionary{\copy\Wrappedvisiblespacebox}{\Wrappedafterbreak} {\kern\fontdimen2\font}% }% % Allow breaks at special characters using \PYG... macros. \Wrappedbreaksatspecials % Breaks at punctuation characters . , ; ? ! and / need catcode=\active \OriginalVerbatim[#1,codes*=\Wrappedbreaksatpunct]% } \makeatother % Exact colors from NB \definecolor{incolor}{HTML}{303F9F} \definecolor{outcolor}{HTML}{D84315} \definecolor{cellborder}{HTML}{CFCFCF} \definecolor{cellbackground}{HTML}{F7F7F7} % prompt \makeatletter \newcommand{\boxspacing}{\kern\kvtcb@left@rule\kern\kvtcb@boxsep} \makeatother \newcommand{\prompt}[4]{ \ttfamily\llap{{\color{#2}[#3]:\hspace{3pt}#4}}\vspace{-\baselineskip} } % Prevent overflowing lines due to hard-to-break entities \sloppy % Setup hyperref package \hypersetup{ breaklinks=true, % so long urls are correctly broken across lines colorlinks=true, urlcolor=urlcolor, linkcolor=linkcolor, citecolor=citecolor, } % Slightly bigger margins than the latex defaults \geometry{verbose,tmargin=1in,bmargin=1in,lmargin=1in,rmargin=1in} \begin{document} \maketitle \hypertarget{importing-necesssary-packages}{% \section{Importing necesssary packages}\label{importing-necesssary-packages}} \begin{tcolorbox}[breakable, size=fbox, boxrule=1pt, pad at break*=1mm,colback=cellbackground, colframe=cellborder] \prompt{In}{incolor}{47}{\boxspacing} \begin{Verbatim}[commandchars=\\\{\}] \PY{k+kn}{import} \PY{n+nn}{pandas} \PY{k}{as} \PY{n+nn}{pd} \PY{k+kn}{from} \PY{n+nn}{numpy} \PY{k+kn}{import} \PY{n}{percentile} \PY{k}{as} \PY{n}{ps} \PY{k+kn}{import} \PY{n+nn}{matplotlib}\PY{n+nn}{.}\PY{n+nn}{pyplot} \PY{k}{as} \PY{n+nn}{plt} \end{Verbatim} \end{tcolorbox} \hypertarget{question-1}{% \subsection{Question 1}\label{question-1}} \hypertarget{reading-data-using-pandas}{% \subsubsection{Reading data using pandas}\label{reading-data-using-pandas}} \begin{tcolorbox}[breakable, size=fbox, boxrule=1pt, pad at break*=1mm,colback=cellbackground, colframe=cellborder] \prompt{In}{incolor}{48}{\boxspacing} \begin{Verbatim}[commandchars=\\\{\}] \PY{n}{bc} \PY{o}{=} \PY{n}{pd}\PY{o}{.}\PY{n}{read\PYZus{}csv}\PY{p}{(}\PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{data.csv}\PY{l+s+s2}{\PYZdq{}}\PY{p}{)} \end{Verbatim} \end{tcolorbox} \hypertarget{question-2}{% \subsection{Question 2}\label{question-2}} \hypertarget{finding-class-distribution}{% \subsubsection{Finding class distribution}\label{finding-class-distribution}} \begin{tcolorbox}[breakable, size=fbox, boxrule=1pt, pad at break*=1mm,colback=cellbackground, colframe=cellborder] \prompt{In}{incolor}{49}{\boxspacing} \begin{Verbatim}[commandchars=\\\{\}] \PY{n}{classes} \PY{o}{=} \PY{n}{bc}\PY{p}{[}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{diagnosis}\PY{l+s+s1}{\PYZsq{}}\PY{p}{]}\PY{o}{.}\PY{n}{unique}\PY{p}{(}\PY{p}{)} \PY{n}{a} \PY{o}{=} \PY{n}{bc}\PY{p}{[}\PY{n}{bc}\PY{p}{[}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{diagnosis}\PY{l+s+s1}{\PYZsq{}}\PY{p}{]}\PY{o}{==}\PY{n}{classes}\PY{p}{[}\PY{l+m+mi}{0}\PY{p}{]}\PY{p}{]} \PY{n}{b} \PY{o}{=} \PY{n}{bc}\PY{p}{[}\PY{n}{bc}\PY{p}{[}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{diagnosis}\PY{l+s+s1}{\PYZsq{}}\PY{p}{]}\PY{o}{==}\PY{n}{classes}\PY{p}{[}\PY{l+m+mi}{1}\PY{p}{]}\PY{p}{]} \PY{n+nb}{print}\PY{p}{(}\PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{Class distribution:}\PY{l+s+se}{\PYZbs{}n}\PY{l+s+s2}{\PYZdq{}}\PY{p}{,}\PY{n}{classes}\PY{p}{[}\PY{l+m+mi}{0}\PY{p}{]}\PY{p}{,}\PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{:}\PY{l+s+s2}{\PYZdq{}}\PY{p}{,}\PY{n+nb}{len}\PY{p}{(}\PY{n}{a}\PY{p}{)}\PY{p}{,}\PY{l+s+s2}{\PYZdq{}}\PY{l+s+se}{\PYZbs{}n}\PY{l+s+s2}{\PYZdq{}}\PY{p}{,}\PY{n}{classes}\PY{p}{[}\PY{l+m+mi}{1}\PY{p}{]}\PY{p}{,}\PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{:}\PY{l+s+s2}{\PYZdq{}}\PY{p}{,}\PY{n+nb}{len}\PY{p}{(}\PY{n}{b}\PY{p}{)}\PY{p}{,}\PY{l+s+s2}{\PYZdq{}}\PY{l+s+se}{\PYZbs{}n}\PY{l+s+s2}{Total records :}\PY{l+s+s2}{\PYZdq{}}\PY{p}{,}\PY{n+nb}{len}\PY{p}{(}\PY{n}{bc}\PY{p}{)}\PY{p}{)} \end{Verbatim} \end{tcolorbox} \begin{Verbatim}[commandchars=\\\{\}] Class distribution: M : 212 B : 357 Total records : 569 \end{Verbatim} \hypertarget{question-3}{% \subsection{Question 3}\label{question-3}} \hypertarget{finding-five-number-summary-and-plotting-boxplot-for-the-same}{% \subsubsection{Finding five number summary and plotting boxplot for the same}\label{finding-five-number-summary-and-plotting-boxplot-for-the-same}} \hypertarget{function-find5ns-takes-as-input-column-number-3-to-32-as-first-two-are-non-numeric-and-also-plot-boolean-which-decides-whether-the-plot-is-drawn-or-not.-it-prints-the-5-number-summary-and-plot-optional}{% \paragraph{Function find5ns( ) takes as input column number (3 to 32, as first two are non numeric) and also plot boolean which decides whether the plot is drawn or not. It prints the 5 number summary and plot (optional)}\label{function-find5ns-takes-as-input-column-number-3-to-32-as-first-two-are-non-numeric-and-also-plot-boolean-which-decides-whether-the-plot-is-drawn-or-not.-it-prints-the-5-number-summary-and-plot-optional}} \begin{tcolorbox}[breakable, size=fbox, boxrule=1pt, pad at break*=1mm,colback=cellbackground, colframe=cellborder] \prompt{In}{incolor}{50}{\boxspacing} \begin{Verbatim}[commandchars=\\\{\}] \PY{n}{headings} \PY{o}{=} \PY{n}{bc}\PY{o}{.}\PY{n}{columns}\PY{o}{.}\PY{n}{tolist}\PY{p}{(}\PY{p}{)} \PY{k}{def} \PY{n+nf}{find5ns}\PY{p}{(}\PY{n}{i}\PY{p}{,}\PY{n}{plot}\PY{p}{)}\PY{p}{:} \PY{n}{quartiles} \PY{o}{=} \PY{n}{ps}\PY{p}{(}\PY{n}{bc}\PY{p}{[}\PY{n}{headings}\PY{p}{[}\PY{n}{i}\PY{p}{]}\PY{p}{]}\PY{p}{,}\PY{p}{[}\PY{l+m+mi}{25}\PY{p}{,}\PY{l+m+mi}{50}\PY{p}{,}\PY{l+m+mi}{75}\PY{p}{]}\PY{p}{)} \PY{n}{bc\PYZus{}min}\PY{p}{,}\PY{n}{bc\PYZus{}max} \PY{o}{=} \PY{n}{bc}\PY{p}{[}\PY{n}{headings}\PY{p}{[}\PY{n}{i}\PY{p}{]}\PY{p}{]}\PY{o}{.}\PY{n}{min}\PY{p}{(}\PY{p}{)}\PY{p}{,}\PY{n}{bc}\PY{p}{[}\PY{n}{headings}\PY{p}{[}\PY{n}{i}\PY{p}{]}\PY{p}{]}\PY{o}{.}\PY{n}{max}\PY{p}{(}\PY{p}{)} \PY{n+nb}{print}\PY{p}{(}\PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{5 number summary of}\PY{l+s+s2}{\PYZdq{}}\PY{p}{,}\PY{n}{headings}\PY{p}{[}\PY{n}{i}\PY{p}{]}\PY{p}{)} \PY{n+nb}{print}\PY{p}{(}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{Min: }\PY{l+s+si}{\PYZpc{}.3f}\PY{l+s+s1}{\PYZsq{}} \PY{o}{\PYZpc{}} \PY{n}{bc\PYZus{}min}\PY{p}{)} \PY{n+nb}{print}\PY{p}{(}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{Q1: }\PY{l+s+si}{\PYZpc{}.3f}\PY{l+s+s1}{\PYZsq{}} \PY{o}{\PYZpc{}} \PY{n}{quartiles}\PY{p}{[}\PY{l+m+mi}{0}\PY{p}{]}\PY{p}{)} \PY{n+nb}{print}\PY{p}{(}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{Median: }\PY{l+s+si}{\PYZpc{}.3f}\PY{l+s+s1}{\PYZsq{}} \PY{o}{\PYZpc{}} \PY{n}{quartiles}\PY{p}{[}\PY{l+m+mi}{1}\PY{p}{]}\PY{p}{)} \PY{n+nb}{print}\PY{p}{(}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{Q3: }\PY{l+s+si}{\PYZpc{}.3f}\PY{l+s+s1}{\PYZsq{}} \PY{o}{\PYZpc{}} \PY{n}{quartiles}\PY{p}{[}\PY{l+m+mi}{2}\PY{p}{]}\PY{p}{)} \PY{n+nb}{print}\PY{p}{(}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{Max: }\PY{l+s+si}{\PYZpc{}.3f}\PY{l+s+s1}{\PYZsq{}} \PY{o}{\PYZpc{}} \PY{n}{bc\PYZus{}max}\PY{p}{)} \PY{k}{if} \PY{n}{plot}\PY{p}{:} \PY{n}{bc}\PY{o}{.}\PY{n}{boxplot}\PY{p}{(}\PY{n}{column} \PY{o}{=} \PY{p}{[}\PY{n}{headings}\PY{p}{[}\PY{n}{i}\PY{p}{]}\PY{p}{]}\PY{p}{)} \end{Verbatim} \end{tcolorbox} \hypertarget{we-can-even-put-it-through-a-simple-for-loop-and-call-the-function-over-every-column-with-ease}{% \paragraph{We can even put it through a simple for loop and call the function over every column with ease}\label{we-can-even-put-it-through-a-simple-for-loop-and-call-the-function-over-every-column-with-ease}} \begin{tcolorbox}[breakable, size=fbox, boxrule=1pt, pad at break*=1mm,colback=cellbackground, colframe=cellborder] \prompt{In}{incolor}{51}{\boxspacing} \begin{Verbatim}[commandchars=\\\{\}] \PY{n}{find5ns}\PY{p}{(}\PY{l+m+mi}{3}\PY{p}{,}\PY{n}{plot}\PY{o}{=}\PY{k+kc}{True}\PY{p}{)} \end{Verbatim} \end{tcolorbox} \begin{Verbatim}[commandchars=\\\{\}] 5 number summary of texture\_mean Min: 9.710 Q1: 16.170 Median: 18.840 Q3: 21.800 Max: 39.280 \end{Verbatim} \begin{center} \adjustimage{max size={0.9\linewidth}{0.9\paperheight}}{output_9_1.png} \end{center} { \hspace*{\fill} \\} \begin{tcolorbox}[breakable, size=fbox, boxrule=1pt, pad at break*=1mm,colback=cellbackground, colframe=cellborder] \prompt{In}{incolor}{52}{\boxspacing} \begin{Verbatim}[commandchars=\\\{\}] \PY{n}{find5ns}\PY{p}{(}\PY{l+m+mi}{4}\PY{p}{,}\PY{n}{plot} \PY{o}{=} \PY{k+kc}{False}\PY{p}{)} \end{Verbatim} \end{tcolorbox} \begin{Verbatim}[commandchars=\\\{\}] 5 number summary of perimeter\_mean Min: 43.790 Q1: 75.170 Median: 86.240 Q3: 104.100 Max: 188.500 \end{Verbatim} \hypertarget{question-4}{% \subsection{Question 4}\label{question-4}} \hypertarget{plotting-boxplot-for-attributes-and-comparing-them-with-respect-to-different-classes}{% \subsubsection{Plotting boxplot for attributes and comparing them with respect to different classes}\label{plotting-boxplot-for-attributes-and-comparing-them-with-respect-to-different-classes}} \hypertarget{to-this-end-ive-written-a-function-that-plots-the-column-that-is-given-as-input-to-the-function-myboxplot-.-it-also-gives-the-5-number-summary-see-previous-for-better-understanding-the-boxplot.}{% \paragraph{To this end i've written a function that plots the column that is given as input to the function myboxplot( ). It also gives the 5 number summary (See previous) for better understanding the boxplot.}\label{to-this-end-ive-written-a-function-that-plots-the-column-that-is-given-as-input-to-the-function-myboxplot-.-it-also-gives-the-5-number-summary-see-previous-for-better-understanding-the-boxplot.}} \begin{tcolorbox}[breakable, size=fbox, boxrule=1pt, pad at break*=1mm,colback=cellbackground, colframe=cellborder] \prompt{In}{incolor}{54}{\boxspacing} \begin{Verbatim}[commandchars=\\\{\}] \PY{k}{def} \PY{n+nf}{myboxplot}\PY{p}{(}\PY{n}{i}\PY{p}{)}\PY{p}{:} \PY{n}{find5ns}\PY{p}{(}\PY{n}{i}\PY{p}{,}\PY{n}{plot} \PY{o}{=} \PY{k+kc}{False}\PY{p}{)} \PY{n}{bc}\PY{o}{.}\PY{n}{boxplot}\PY{p}{(}\PY{n}{column} \PY{o}{=} \PY{p}{[}\PY{n}{headings}\PY{p}{[}\PY{n}{i}\PY{p}{]}\PY{p}{]}\PY{p}{,} \PY{n}{by} \PY{o}{=} \PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{diagnosis}\PY{l+s+s1}{\PYZsq{}}\PY{p}{)} \end{Verbatim} \end{tcolorbox} \hypertarget{similar-to-previous-cases-we-can-use-a-for-loop-to-plot-for-all-columns-to-enhance-understanding-or-specify-columns-we-want.}{% \paragraph{Similar to previous cases, we can use a for loop to plot for all columns to enhance understanding or specify columns we want.}\label{similar-to-previous-cases-we-can-use-a-for-loop-to-plot-for-all-columns-to-enhance-understanding-or-specify-columns-we-want.}} \begin{tcolorbox}[breakable, size=fbox, boxrule=1pt, pad at break*=1mm,colback=cellbackground, colframe=cellborder] \prompt{In}{incolor}{56}{\boxspacing} \begin{Verbatim}[commandchars=\\\{\}] \PY{n}{myboxplot}\PY{p}{(}\PY{l+m+mi}{3}\PY{p}{)} \end{Verbatim} \end{tcolorbox} \begin{Verbatim}[commandchars=\\\{\}] 5 number summary of texture\_mean Min: 9.710 Q1: 16.170 Median: 18.840 Q3: 21.800 Max: 39.280 \end{Verbatim} \begin{center} \adjustimage{max size={0.9\linewidth}{0.9\paperheight}}{output_14_1.png} \end{center} { \hspace*{\fill} \\} \begin{tcolorbox}[breakable, size=fbox, boxrule=1pt, pad at break*=1mm,colback=cellbackground, colframe=cellborder] \prompt{In}{incolor}{57}{\boxspacing} \begin{Verbatim}[commandchars=\\\{\}] \PY{n}{myboxplot}\PY{p}{(}\PY{l+m+mi}{5}\PY{p}{)} \end{Verbatim} \end{tcolorbox} \begin{Verbatim}[commandchars=\\\{\}] 5 number summary of area\_mean Min: 143.500 Q1: 420.300 Median: 551.100 Q3: 782.700 Max: 2501.000 \end{Verbatim} \begin{center} \adjustimage{max size={0.9\linewidth}{0.9\paperheight}}{output_15_1.png} \end{center} { \hspace*{\fill} \\} \hypertarget{question-5}{% \subsection{Question 5}\label{question-5}} \hypertarget{plot-histogram-for-attributes}{% \subsubsection{Plot histogram for attributes}\label{plot-histogram-for-attributes}} \hypertarget{the-function-plothist-plots-histogram-for-selected-columns.-plotting-all-columns-is-possible-but-is-not-plausible-because-no-inference-can-be-drawn-because-of-too-many-attributes.}{% \paragraph{The function plothist( ) plots histogram for selected columns. Plotting all columns is possible but is not plausible because no inference can be drawn because of too many attributes.}\label{the-function-plothist-plots-histogram-for-selected-columns.-plotting-all-columns-is-possible-but-is-not-plausible-because-no-inference-can-be-drawn-because-of-too-many-attributes.}} \begin{tcolorbox}[breakable, size=fbox, boxrule=1pt, pad at break*=1mm,colback=cellbackground, colframe=cellborder] \prompt{In}{incolor}{58}{\boxspacing} \begin{Verbatim}[commandchars=\\\{\}] \PY{k}{def} \PY{n+nf}{plothist}\PY{p}{(}\PY{n}{i}\PY{p}{)}\PY{p}{:} \PY{n}{bc}\PY{p}{[}\PY{n}{headings}\PY{p}{[}\PY{n}{i}\PY{p}{]}\PY{p}{]}\PY{o}{.}\PY{n}{plot}\PY{o}{.}\PY{n}{hist}\PY{p}{(}\PY{n}{bins}\PY{o}{=}\PY{l+m+mi}{20}\PY{p}{,} \PY{n}{alpha} \PY{o}{=} \PY{l+m+mf}{0.7}\PY{p}{,}\PY{n}{rwidth}\PY{o}{=}\PY{l+m+mf}{0.85}\PY{p}{)} \PY{n}{plt}\PY{o}{.}\PY{n}{xlabel}\PY{p}{(}\PY{n}{headings}\PY{p}{[}\PY{n}{i}\PY{p}{]}\PY{p}{)} \PY{n}{plt}\PY{o}{.}\PY{n}{title}\PY{p}{(}\PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{Histogram of }\PY{l+s+s2}{\PYZdq{}}\PY{o}{+}\PY{n}{headings}\PY{p}{[}\PY{n}{i}\PY{p}{]}\PY{p}{)} \PY{n}{plt}\PY{o}{.}\PY{n}{grid}\PY{p}{(}\PY{n}{axis}\PY{o}{=}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{y}\PY{l+s+s1}{\PYZsq{}}\PY{p}{,} \PY{n}{alpha}\PY{o}{=}\PY{l+m+mf}{0.75}\PY{p}{)} \PY{n}{find5ns}\PY{p}{(}\PY{n}{i}\PY{p}{,}\PY{n}{plot} \PY{o}{=} \PY{k+kc}{False}\PY{p}{)} \end{Verbatim} \end{tcolorbox} \hypertarget{similar-to-previous-cases-ive-maintained-modularity-so-this-function-can-be-used-in-a-for-loop-or-on-a-specific-column.-it-displays-the-5-number-summary-so-we-can-better-understand-the-plotted-distribution}{% \paragraph{Similar to previous cases I've maintained modularity, so this function can be used in a for loop or on a specific column. It displays the 5 number summary so we can better understand the plotted distribution}\label{similar-to-previous-cases-ive-maintained-modularity-so-this-function-can-be-used-in-a-for-loop-or-on-a-specific-column.-it-displays-the-5-number-summary-so-we-can-better-understand-the-plotted-distribution}} \begin{tcolorbox}[breakable, size=fbox, boxrule=1pt, pad at break*=1mm,colback=cellbackground, colframe=cellborder] \prompt{In}{incolor}{59}{\boxspacing} \begin{Verbatim}[commandchars=\\\{\}] \PY{n}{plothist}\PY{p}{(}\PY{l+m+mi}{3}\PY{p}{)} \end{Verbatim} \end{tcolorbox} \begin{Verbatim}[commandchars=\\\{\}] 5 number summary of texture\_mean Min: 9.710 Q1: 16.170 Median: 18.840 Q3: 21.800 Max: 39.280 \end{Verbatim} \begin{center} \adjustimage{max size={0.9\linewidth}{0.9\paperheight}}{output_19_1.png} \end{center} { \hspace*{\fill} \\} As we can see in the above case. The 5 number summary is graphically depicted. The median is pretty close to the mean. It is a good example of a bell curve with a relatively narrow distribution. The example on the far right could be a possible outlier. \begin{tcolorbox}[breakable, size=fbox, boxrule=1pt, pad at break*=1mm,colback=cellbackground, colframe=cellborder] \prompt{In}{incolor}{60}{\boxspacing} \begin{Verbatim}[commandchars=\\\{\}] \PY{n}{plothist}\PY{p}{(}\PY{l+m+mi}{5}\PY{p}{)} \end{Verbatim} \end{tcolorbox} \begin{Verbatim}[commandchars=\\\{\}] 5 number summary of area\_mean Min: 143.500 Q1: 420.300 Median: 551.100 Q3: 782.700 Max: 2501.000 \end{Verbatim} \begin{center} \adjustimage{max size={0.9\linewidth}{0.9\paperheight}}{output_21_1.png} \end{center} { \hspace*{\fill} \\} The above histogram is of the area of the cell. Not really a perfect gaussian distributin. It is skewed towards the left side. The examples on the far right are possible outliers. Most distributions are between minimum and Q3 values. \begin{tcolorbox}[breakable, size=fbox, boxrule=1pt, pad at break*=1mm,colback=cellbackground, colframe=cellborder] \prompt{In}{incolor}{ }{\boxspacing} \begin{Verbatim}[commandchars=\\\{\}] \end{Verbatim} \end{tcolorbox} % Add a bibliography block to the postdoc \end{document}
\documentclass[../main.tex]{subfiles} \begin{document} \begin{mdframed} \fullcite{Michalewicz:1996:GAD:229930} \end{mdframed} There are 3 constraint-handling techniques considered in this chapter. \begin{enumerate} \item \textbf{Penalty:} Generate solutions without considering constraints but decrease their ``goodness'' in the evaluation function. The problem is converted to an unconstrained problem with a penalty function. The penalty can either be constant or in function of the violation. The extreme is eliminating non-feasible solution with a death- penalty. \item \textbf{Repair:} Correct the infeasible solutions. However, they might be computationally intensive and require to be tailored to the application. \item \textbf{Decoder:} Use a special representation mapping (decoder) which guarantees the generation of a feasible solution. Alternatively use problem-specific operations. Frequently, this might not be feasible for all constraints and is rather computationally intensive. \end{enumerate} \section{The 0/1 Knapsack Problem} The knapsack problem is used to evaluate the 3 techniques. The problem consists of a capacity limited bag, and items with weights and profits. The goal is to maximize the profit under the constraint that the sum of weights cannot exceed the capacity of the sack. \section{The Test Data} The difficulty of the problem is greatly affected by the correlation between profits and weights. We consider 3 cases. \begin{enumerate} \item \textbf{Uncorrelated:} Both the weight and profit are distributed uniformly random ($[1 \mathellipsis v]$). \item \textbf{Weakly correlated:} The weight is distributed uniformly random. Profits are associated with weights by a random factor ($[1 \mathellipsis r]$). \item \textbf{Strongly correlated:} The weight is distributed uniformly random. Profits are associated with weight by a fixed factor ($r$). \end{enumerate} Higher correlations implies a smaller value of the difference: \begin{equation} \text{max}_{i=1 \mathellipsis n} { P[i]/W[i]} - \text{min}_{i=1 \mathellipsis n} { P[i]/W[i]} \end{equation} Higher correlation problems have higher expected difficulty. Two knapsacks are considered: \begin{itemize} \item \textbf{Restrictive Knapsack Capacity:} Here $C_1 = 2v$. The optimal solution contains very few items. \item \textbf{Average Knapsack Capacity:} Here $C_2 = \frac{1}{2} \sum^n_{i=1}W[i]$. About half the items are in the optimal solution. \end{itemize} \section{Algorithms} \subsection{Penalty Algorithms} The solution is represented by a binary string of length $n$: the $i$-th item is selected for the knapsack when $x[i] = 1$. The fitness is given by \begin{equation} \text{eval}(x) = \sum^n_{i=1} x[i] \cdot P[i] - \text{Pen}(x) \end{equation} Three different strategies for assigning penalties are considered. In all cases $\rho = \text{max}_{i=1 \mathellipsis n} { P[i]/W[i]}$. \begin{itemize} \item \textbf{Logarithmic} \\ \[ A_p[1]: \text{Pen}(x) = log_2(1 + \rho \cdot (\sum^n_{i=1} x[i] \cdot P[i] - C)) \] \item \textbf{Linear} \[ A_p[2]: \text{Pen}(x) = \rho \cdot (\sum^n_{i=1} x[i] \cdot P[i] - C) \] \item \textbf{Quadratic} \[ A_p[1]: \text{Pen}(x) = (\rho \cdot (\sum^n_{i=1} x[i] \cdot P[i] - C))^2 \] \end{itemize} \subsection{Repair Algorithms} The same representation is used as in the previous section. The evaluation function is very similar but lack the penalty function. \begin{equation} \text{eval}(x) = \sum^n_{i=1} x[i] \cdot P[i] \end{equation} Two repair algorithms are considered that only differ in the selection procedure. \begin{itemize} \item \textbf{Random Repair} $A_r[1]$: A random item is removed from the knapsack until it is no longer overfilled. \item \textbf{Greedy Repair} $A_r[2]$: All items in the knapsack are sorted in decreasing order of profit-to-weight ratio. The last items are removed from the knapsack until it is no longer overfilled. \end{itemize} \subsection{Decoder Algorithms} The ordinal representation is used for representing chromosomes. The $i$-th element is always in the range of $[1 \mathellipsis n - i + 1]$. The one-point crossover operator applied to any valid chromosome will generate a valid solution. Two build procedures are considered: \begin{itemize} \item \textbf{Random Decoding} $A_d[1]$: The representation is created such that the order of items corresponds with the order in the input. \item \textbf{Greedy Decoding} $A_d[2]$: The representation is created such that the order of items is decreasing in the profit-to-weight ratio. \end{itemize} \section{Results} \begin{itemize} \item Penalty functions $A_p[i]$ do not produce feasible results for problems with restrictive capacity ($C_1$). \item Considering average capacity ($C_2$) problems, the logarithmic penalty function outperforms all others. \item Considering restrictive capacity ($C_2$) problems, the greedy repair method $A_r[2]$ outperforms all other methods. \end{itemize} The results are intuitive: for the restrictive problem, only a small fraction constitute the feasible solution. The smaller the ratio between the feasible part and the search space, the harder for the penalty methods to provide feasible results. \end{document}
\chapter*{Abstract} % ne pas numéroter \label{chap:abstract} % étiquette pour renvois \phantomsection\addcontentsline{toc}{chapter}{\nameref{chap:abstract}} % inclure dans TdM \begin{otherlanguage*}{english} This thesis discusses the use of bandit methods to solve the problem of training extractive abstract generation models. The extractive models, which build summaries by selecting sentences from an original document, are difficult to train because the target summary of a document is usually not built in an extractive way. It is for this purpose that we propose to see the production of extractive summaries as different bandit problems, for which there exist algorithms that can be leveraged for training summarization models. In this paper, BanditSum is first presented, an approach drawn from the literature that sees the generation of the summaries of a set of documents as a contextual bandit problem. Next, we introduce CombiSum, a new algorithm which formulates the generation of the summary of a single document as a combinatorial bandit. By exploiting the combinatorial formulation, CombiSum manages to incorporate the notion of the extractive potential of each sentence of a document in its training. Finally, we propose LinCombiSum, the linear variant of CombiSum which exploits the similarities between sentences in a document and uses the linear combinatorial bandit formulation instead. \end{otherlanguage*}
\chapter{Calibration} Our goal is to create a system which does not need any prior information about the position of cameras. Since we do not know how far away the cameras are, nor angles between them, we firstly use calibration to obtain this information. By calibrating cameras with a well describable pattern, we can obtain information about the single camera, such as what distortion its lens cause, or how the world points are projected to an image plane of the camera. After discovering these parameters for both cameras, we will continue on stereo calibration. Stereo calibration will provide us information about their position in space relative to each other. For these calibration processes, we use algorithms implemented in OpenCV. Therefore, we provide only a short overview of the process, and we describe only results obtained from calibration essential to us. \section{Intrinsic parameters} Each camera type is different. Moreover, each camera of a specific type is different due to a manufacturing process. Therefore we introduce intrinsic camera parameters, which help us to model the camera precisely. Intrinsic camera parameters define a transformation between the world coordinates and the coordinates within an image plane (in pixels). Physical attributes of the camera influence this transformation. These parameters include focal length, a position of the principal point and distortion coefficients. All these parameters are needed to get a correct transformation between the point in the space and the point at the image plane. Sometimes even more parameters are used for a better description of the model of the camera. \subsection{Camera matrix} Camera matrix will provide us a transformation from world coordinates (with the origin in the camera) to image plane coordinates (seen in the image taken from the camera). If the coordinates in 3D are available, we can obtain 2D coordinates by simple multiplication by camera matrix. After multiplication we obtain 2D homogeneous coordinates. As the next step, we describe the camera matrix obtained by OpenCV calibration procedure. In the OpenCV implementation the camera matrix is $3\times3$ matrix of the following format: \[ \begin{pmatrix} f_x & 0 & c_x \\ 0 & f_y & c_y \\ 0 & 0 & 1 \end{pmatrix} \] Where $f_x$, $f_y$ denote focal lengths expressed in pixel units. It is usual to introduce two of them, separately for both axes, since pixels usually are not perfect squares but rather rectangles. Therefore the same focal length, has different length in pixel units over a given axis. We refer the ray of the view of the camera as the principal ray. The point where this ray intersects the image plane is called principal point\footnote{For more information visit \url{https://en.wikipedia.org/wiki/Pinhole\_camera\_model\#The\_geometry\_and\_mathematics\_of\_the\_pinhole\_camera}}. Parameters $c_x$ and $c_y$ define coordinates of the principal point in the image plane. It should be the center of the image, but assembling process of the camera might cause a small displacement. \subsection{Distortion coefficients} Cameras are equipped with lenses to obtain sharp image instead of blurry. The lens may causes various distortions. Fish-Eye lenses are known for their distortion. Even web camera lenses have distortion, but not as visible as the camera with a fish-eye lens. It is important to correct these distortions. Two distortion types cause a significant effect on the image. The first one is the radial distortion, creating barrel effect and the second one tangential distortion. The radial distortion is caused by the camera lens (the effect of radial distortion is displayed in the image \ref{fig:distortion}). It can usually be described by three parameters. Highly distorted images (like from fish-eye) often need more parameters. Since our system use web cameras, we will use only three parameters. In the ideal camera, the lens would be placed parallel to the chip. Since such precision is not possible, due to an assembling process, tangential distortion arises. For this distortion, we use two parameters. We describe both distortion effects by five parameters. More about the meaning of the parameters could be found in the book by \citet*{bradski2008learning}. \begin{figure} \begin{subfigure}[b]{0.48\linewidth} \includegraphics[width=\linewidth]{img/chessboard/7x8chessboard-positivedistortion} \caption{Effect of positive radial distortion} \end{subfigure} \begin{subfigure}[b]{0.48\linewidth} \includegraphics[width=\linewidth]{img/chessboard/7x8chessboard-negativedistortion} \caption{Effect of negative radial distortion} \end{subfigure} \caption{Effects of lens distortion on the image of the chessboard} \label{fig:distortion} \end{figure} These nine parameters (four for camera matrix and five for distortion coefficients) describe the camera model. They may be used for example for projecting a point from 3D space to image coordinates in the camera (OpenCV function \verb+projectPoints+). We will use them to get better results for stereo calibration and for localization, since they provide us a more accurate model of the camera. %We can now describe the transformation process in one camera by multiplication by %the camera matrix and then correcting the results by distortion coefficients. With %these parameters, we can continue on stereo calibration. %\todo[inline]{Ale co se pronasobi tou matici?} %\todo[inline]{Napis sem ten vzorecek} \section{Stereo calibration} After performing a calibration of both cameras separately, we also need information about their relative position to each other. By the relative position, we understand translation from the first camera to the second and the rotation of the camera (among three axes). Using this information, we can transform a view of the one camera, by moving it by translation vector and rotating accordingly. Therefore, the position of the second camera can be described by six parameters, three as an angle around each axis to rotate and three for translation vector in respect to the first camera. Stereo calibration routine in OpenCV can also perform mono calibration for both cameras, but we pre-calibrate cameras on itself for better precision and better convergence of the algorithm. Stereo calibration routine will provide more information. For the goals of this thesis, only rotation matrix and translation vector are important. \section{Calibration process} In previous sections we shortly discussed theoretical background behind the calibration. In this section we will focus on the implementation. In OpenCV a chessboard is commonly used, since it is a planar object (easy to reproduce by printing) and well described. OpenCV also provides methods for automatic finding of the chessboard in the picture, so no human intervention is needed to select the chessboard corners from the image (an example of the chessboard is provided in a Figure \ref{fig:chessboard}). Therefore, we also use the chessboard pattern for calibration. \begin{figure} \centering \includegraphics[width=0.8\linewidth]{img/chessboard/7x8chessboard} \caption{Example of $7\times8$ chessboard used for the calibration} \label{fig:chessboard} \end{figure} \subsection{How many images?} Now we know that, we can use a chessboard to calibrate the cameras. However, the question of how many images are needed for the calibration remains. We discuss only the images where the full chessboard is found. For enough information from each image, we need a chessboard with at least $3\times3$ inner corners. It is better to have a chessboard with even, and odd dimension (for example 7$\times$ 8 inner corners) since it has only one symmetry axis, and the pose of the object can be detected correctly. It is important that the chessboard indeed has squares, not rectangles (so it is better to check it after printing). A bigger chessboard is easier to recognize, so we recommend at least format A4. We need only one image for computing the distortion coefficients. However, for the camera matrix, we need at least two images. For stereo calibration, we need at least one pair of images of the chessboard. We know the minimum number of images needed for calibration. On the other hand, we use more images for the robustness of the algorithm. We need a ``rich'' set of views. Therefore it is important to move the chessboard between snapshots. With more provided information to the algorithm, it compensates the errors in the measurements (like a wrongly detected chessboard in one of the images). Therefore also the computation time increases. Since it is enough for a given setup of the cameras to perform a calibration only once and then use results from it again, we recommend to do the calibration on more images and wait a little bit longer for the results.
\chapter{Heading in Booktype} NORMAL PARAGRAPH IN BOOKTYPE this chapter is meant to show all stuff that can be done in Booktype in XeTex. Left Munich at 8:35 P. M., on 1st May, arriving at Vienna early next morning; should have arrived at 6:46. \section{SubHeading in Booktype} \subsection{SubSubHeading in Booktype} Pre-formatted \begin{verbatim} This is a table using white spaces only! \end{verbatim} QUOTE \begin{quote} QUOTE \lipsum[1] \end{quote} \begin{quotation} QUOTATION arrived at 6:46, but train was an hour late. Buda-Pesth seems a wonderful place, from the glimpse which I got of it from the train and the little I could walk through the streets. I feared to go very far from the station, as we had arrived late and would start as near the correct time as possible. The impression I had was that we were leaving the West and ent. \end{quotation} \begin{verse} VERSE arrived at 6:46, but train was an hour late. Buda-Pesth seems a wonderful place, from the glimpse which I got of it from the train and the little I could walk through the streets. I feared to go very far from the station, as we had arrived late and would start as near the correct time as possible. The impression I had was that we were leaving the West and ent \end{verse} \subsubsection{Font formatting} Text you want \underline{underlined goes here.} \blindtext I want to \emph{emphasize} a word. \emph{In this emphasized sentence, there is an emphasized \emph{word} which looks upright.} \textbf{Bold text} may be used to heavily emphasize very important words or phrases. \textit{Italicised text} may be used to lightly emphasize words or phrases. You can also combing \textit{italicised and \textbf{bold text}} as shown here. Or the other way around, combine \textbf{bold and \textit{italicised text}} as shown here. There is \textbf{bold text and} \textmd{medium weight text} - a subtle distinction. Monospace font like Courier is called \texttt{teletype font}. \textsf{Sans serif font family} is being used at the beginning of this sentence. A neat little feature is the \textsc{Small Caps Feature applied here} or the {\scshape Small Caps Feature applied here}. Old style numbers look like this: {\addfontfeature{Numbers=OldStyle}1234567890}. If old style is set in the preamble then these should also be old style: 1234567890. Of course you can also \uppercase{shout it all in uppercase}. \tiny{tiny sample text} \scriptsize{scriptsize sample text} \footnotesize{footnotesize sample text} \small{small sample text} \normalsize{normalsize sample text} \large{large sample text} \Large{Large sample text} \LARGE{LARGE sample text} \huge{huge sample text} \Huge{Huge sample text} \normalsize \subsubsection{Links, URLs} Here's a link to \href{http://twitter.com/home}{Twitter}. And here is a link to \url{http://booktype.pro} \subsubsection{Left align} \begin{flushleft} \lipsum[1] \end{flushleft} \subsubsection{Right align} \begin{flushright} \lipsum[1] \end{flushright} \subsubsection{Center align} \begin{center} \lipsum[1] \end{center} \subsubsection{Justify / Blocksatz} Back to normal, which is justified text. \lipsum[1] \subsubsection{indent a paragraph} \lipsum[1] \begin{adjustwidth}{2cm}{} \lipsum[1] \end{adjustwidth} \begin{adjustwidth}{4cm}{} \lipsum[1] \end{adjustwidth} \begin{adjustwidth}{2cm}{} \lipsum[1] \end{adjustwidth} \lipsum[1] \subsubsection{Lists} \begin{itemize} \item The first item \item The second item \item The third etc \ldots \end{itemize} \begin{enumerate} \item The first item \item The second item \item The third etc \ldots \end{enumerate} \begin{itemize} \item \blindtext \item \blindtext \end{itemize} \begin{enumerate} \item \blindtext \item \blindtext \end{enumerate} \subsubsection{Font sizes} \font\FontSizeTenPT="Ubuntu" at 10pt \font\testhuge="Ubuntu" at 100pt \font\testbig="Ubuntu" at 80pt \font\testnormal="Ubuntu" at 50pt \font\testsmall="Ubuntu" at 40pt \font\testtiny="Ubuntu" at 24pt \offinterlineskip\testnormal {\FontSizeTenPT 10pt is the size of this} {\testhuge ABCDE} \vskip1pt {\testbig ABCDE} \vskip1pt ABCDE \vskip1pt {\testsmall ABCDE} \vskip1pt {\testtiny ABCDE} \normalsize \chapter{Chapter title and text examples} Paragraph style "Normal Text" Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. \begin{quote} Paragraph style "Quote" Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy (press Shift+Return for single line breaks)\\ eirmod tempor invidunt \end{quote} Now we will do some font size. Booktype gives me the option to select one of the following font sizes: \font\FontSizeTenPT="Ubuntu" at 10pt \font\FontSizeTwelvePT="Ubuntu" at 12pt \font\FontSizeFourteenPT="Ubuntu" at 14pt \font\FontSizeSixteenPT="Ubuntu" at 16pt \font\FontSizeEighteenPT="Ubuntu" at 18pt \font\FontSizeTwentyPT="Ubuntu" at 20pt \font\FontSizeTwentytwoPT="Ubuntu" at 22pt \font\FontSizeTwentyfourPT="Ubuntu" at 24pt \font\FontSizeTwentysixPT="Ubuntu" at 26pt \font\FontSizeTwentyeightPT="Ubuntu" at 28pt \font\FontSizeThirtyPT="Ubuntu" at 30pt {\FontSizeTenPT 10pt is the size of this paragraph.} {\FontSizeTwelvePT 12pt is the size of this paragraph.} {\FontSizeFourteenPT 14pt is the size of this paragraph.} {\FontSizeSixteenPT 16pt is the size of this paragraph.} {\FontSizeEighteenPT 18pt is the size of this paragraph.} {\FontSizeTwentyPT 20pt is the size of this paragraph.} {\FontSizeTwentytwoPT 22pt is the size of this paragraph.} {\FontSizeTwentyfourPT 24pt is the size of this paragraph.} {\FontSizeTwentysixPT 26pt is the size of this paragraph.} {\FontSizeTwentyeightPT 28pt is the size of this paragraph.} {\FontSizeThirtyPT 30pt is the size of this paragraph.} \chapter{Style "Heading" and colours} Paragraph style "Normal Text" with a couple of font styles. Here is \textbf{some bold text}. And here is \textit{some italicised text}. Part of this sentence is underlined. We can also combine these, starting \textit{italicise now, \textbf{then some bold}, back to italics only} and back to normal. This can also happen the other way around: \textbf{starting bold now, \textit{then some italics}, back to bold only} and back to normal. % http://www.andy-roberts.net/writing/latex/tables \noindent \begin{table} % hide table numbering if set for list of tables or chapters in general % set in theme variables \ifnum\pdfstrcmp{\varShowToTablesNumbering}{false}=0 \caption*{Just a few names in this table} \else \ifnum\pdfstrcmp{\varChapterWriteNumbering}{false}=0 \caption*{Just a few names in this table} \else \caption{Just a few names in this table} \fi \fi \begin{center} \begin{tabular}{lllll} \toprule Feature & Icon & Description & HTML & LaTeX \\ \midrule Bold & Fat B & Makes the font look fatter & <b> or <strong> & textbf \\ Bold & Fat B & Makes the font look fatter & <b> or <strong> & textbf \\ \bottomrule \end{tabular} \end{center} \end{table} Here is a coloured piece of text: \textcolor[rgb]{1,0,0}{This is \textbf{red}.} \textcolor[rgb]{0,0,1}{And this is \textbf{blue}.} \textcolor[rgb]{0,1,0}{This is \textit{green}.} \textcolor[rgb]{0.5,0.5,0.5}{\textbf{And pale are you}.} \section{Style "Subheading", tables and links} At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr. And let's now insert a table:
\chapter{Verification} % Provide the verification approaches and methods planned to qualify the software. The information % items for verification are recommended to be given in a parallel manner with the information items in % 9.6.10 to 9.6.18.
\documentclass[12pt]{amsart} \usepackage{graphicx} \usepackage{amsmath} \usepackage[pdftex]{hyperref} \setlength{\textwidth}{6.2in} \setlength{\textheight}{8.4in} \setlength{\topmargin}{0.2in} \setlength{\oddsidemargin}{0in} \setlength{\evensidemargin}{0in} \setlength{\headsep}{.3in} \footskip 0.3in \newtheorem{thm}{Theorem} \newtheorem{lemma}[thm]{Lemma} \newtheorem{prop}[thm]{Proposition} \newtheorem{cor}[thm]{Corollary} \theoremstyle{definition} \newtheorem{defn}[thm]{Definition} \newtheorem{example}[thm]{Example} \newtheorem{remark}[thm]{Remark} \newtheorem{conj}[thm]{Conjecture} \newcommand{\cherry}[1]{\ensuremath{\langle #1 \rangle}} \newcommand{\ignore}[1]{} \newcommand{\half}{\frac{1}{2}} \newcommand{\eopf}{\framebox[6.5pt]{} \vspace{0.2in}} %------------------document begins----------------------- \begin{document} \title{Methods of Cufflinks} \author{Cole Trapnell \and Lior Pachter} %\address{} %\email{\{whoweare\}@math.berkeley.edu} %\dedicatory{\today} %\thanks{Supported in part by ....} %\subjclass{Primary 55M20; Secondary 47H10} \maketitle \markboth{C Trapnell and L Pachter}{Methods of Cufflinks} This document describes the methods used in the Cufflinks RNA-Seq analysis program. %\pagestyle{plain} \pagenumbering{roman} \tableofcontents \listoffigures \listoftables \newpage \pagenumbering{arabic} \section{Version 0.8.3} \subsection{Transcript abundance estimation \label{abundances}} \label{sec:abundances} \subsubsection{Definitions} A {\em transcript} is an RNA molecule that has been transcribed from DNA. A {\em primary transcript} is an RNA molecule that has yet to undergo modification. The {\em genomic location} of a primary transcript consists of a pair of coordinates in the genome representing the $5'$ transcription start site and the $3'$ polyadenylation cleavage site. We denote the set of all transcripts in a transcriptome by $T$. We partition transcripts into {\em transcription loci} (for simplicity we refer to these as loci) so that every locus contains a set of transcripts all of whose genomic locations do not overlap the genomic location of any transcript in any other locus. Formally, we consider a maximal partition of transcripts into loci, a partition denoted by $G$, where the genomic location of a transcript $t \in g \in G$ does not overlap the genomic location of any transcript $u $ where $u \in h \in G$ and $h \neq g$. We emphasize that the definition of a transcription locus is not biological; transcripts in the same locus may be regulated via different promoters, and may differ completely in sequence (for example if one transcript is in the intron of another) or have different functions. The reason for defining loci is that we will see that they are computationally convenient. We assume that at the time of an experiment, a transcriptome consists of an ensemble of transcripts $T$ where the proportion of transcript $t \in T$ is $\rho_t$, so that $\sum_{t \in T} \rho_t = 1$ and $0 \leq \rho_t \leq 1$ for all $t \in T$. Formally, a {\em transcriptome} is a set of transcripts $T$ together with the abundances $\rho=\{ \rho_t\}_{t \in T}$. For convenience we also introduce notation for the proportion of transcripts in each locus. We let $\sigma_g = \sum_{t \in g} \rho_t$. Similarly, within a locus $g$, we denote the proportion of each transcript $t \in g$ by $\tau_t = \frac{\rho_t}{\sigma_g}$. We refer to $\rho,\sigma$ and $\tau$ as {\em transcript abundances}. Transcripts have lengths, which we denote by $l(t)$. For a collection of transcripts $S \subset T$ in a transcriptome, we define the length of $S$ using the weighted mean: \begin{equation} \label{eq:effective_length} l(S) =\frac{\sum_{t \in S} \rho_tl(t)}{\sum_{t \in S}\rho_t}. \end{equation} It is important to note that the length of a set of transcripts depends on their relative abundances; the reason for this will be clear later. One grouping of transcripts that we will focus on is the set of transcripts within a locus that share the same transcription start site (TSS). Unlike the concept of a locus, grouping by TSS has a biological basis. Transcripts within such a group are by definition alternatively spliced, and if they have different expression levels, this is most likely due to the spliceosome and not due to differences in transcriptional regulation. \subsubsection{A statistical model for RNA-Seq} In order to analyze expression levels of transcripts with RNA-Seq data, it is necessary to have a model for the (stochastic) process of sequencing. A {\em sequencing experiment} consists of selecting a total of $M$ fragments of transcripts uniformly at random from the transcriptome. Each fragment is identified by sequencing from its ends, resulting in two reads called {\em mate pairs}. The length of a fragment is a random variable, with a distribution we will denote by $F$. That is, the probability that a fragment has length $i$ is $F(i)$ and $\sum_{i=1}^{\infty} F(i) = 1$. In this paper we assume that $F$ is normal, however in principle $F$ can be estimated using data from the experiment (e.g. spike-in sequences). We decided to use the normal approximation to $F$ (allowing for user specified parameters of the normal distribution) in order to simplify the requirements for running {\tt Cufflinks} at this time. The assumption of random fragment selection is known to oversimplify the complexities of a sequencing experiment, however without rigorous ways to normalize we decided to work with the uniform at random assumption. It is easy to adapt the model to include more complex models that address sequencing bias as RNA-Seq experiments mature and the technologies are better understood. The transcript abundance estimation problem in paired-end RNA-Seq is to estimate $\rho$ given a set of transcripts $T$ and a set of reads sequenced from the ends of fragments. In {\tt Cufflinks}, the transcripts $T$ can be specified by the user, or alternatively $T$ can be estimated directly from the reads. The latter problem is the transcript assembly problem which we discuss in Section \ref{sec:assembly}. We ran {\tt Cufflinks} in the latter ``discovery'' mode where we assembled the transcripts without using the reference annotation. The fact that fragments have different lengths has bearing on the calculation of the probability of selecting a fragment from a transcript. Consider a transcript $t$ with length $l(t)$. The probability of selecting a fragment of length $k$ from $t$ at one of the positions in $t$ assuming that it is selected uniformly at random, is $\frac{1}{l(t)-k}$. For this reason, we will define an adjusted length for transcripts as \begin{equation} \tilde{l}(t) = \sum_{i=1}^{l(t)} F(i)(l(t)-i+1). \end{equation} We also revisit the definition of length for a group of transcripts, and define \begin{equation} \tilde{l}(S) =\frac{\sum_{t \in S} \rho_t\tilde{l}(t)}{\sum_{t \in S}\rho_t}. \end{equation} It is important to note that given a read it may not be obvious from which transcript the fragment it was sequenced from originated. The consistency of fragments with transcripts is important and we define the {\em fragment-transcript matrix} $A_{R,T}$ to be the $M \times |T|$ matrix with $A(r,t)=1$ if the fragment alignment $r$ is completely contained in the genomic interval spanned by $t$, and all the implied introns in $r$ match introns in $t$ (in order), and with $A(r,t)=0$ otherwise. Note that the reads in Figure 1c in the main text are colored according to the matrix $A_{R,T}$, with each column of the matrix corresponding to one of the three colors (yellow, blue, red) and reads colored according to the mixture of colors corresponding to the transcripts their fragments are contained in. Even given the read alignment to a reference genome, it may not be obvious what the length of the fragment was. Formally, in the case that $A_{R,T}(r,t)=1$ we denote by $I_t(r)$ the fragment length from within a transcript $t$ implied by the (presumably unique) sequences corresponding to the mate pairs of a fragment $r$. If $A_{R,T}(r,t)=0$ then $I_t(r)$ is set to be infinite and $F(I_t(r)) = 0$. Given a set of reads, we assume that we can identify for each of them the set of transcripts with which the fragments the reads belonged to are consistent. The rationale for this assumption is the following: we map the reads to a reference genome, and we assume that the read lengths are sufficiently long so that every mate-pair can be uniquely mapped to the genome. We refer to this mapping as the {\em fragment alignment}. We also assume that we know all the possible transcripts and their alignments to the genome. Therefore, we can identify for each read the possible transcripts from which the fragment it belonged to originated. \begin{figure}[!ht] \includegraphics[scale=0.8]{pdfs/implied_length} \caption[Implied length of a fragment alignment]{Alignments of reads to the genome (rectangles) may be consistent with multiple transcripts (in this case both $t_1$ and $t_2$). The transcripts $t_1$ and $t_2$ differ by an internal exon; introns are indicated by long dashed lines. If we denote the fragment alignment by $r$, this means that $A_{R,T}(r,t_1)=1$ and $A_{R,T}(r,t_2)=1$. It is apparent that the implied length $I_{t_1}(r) > I_{t_2}(r)$ due to the presence of the extra internal exon in $t_1$. } \end{figure} We are now ready to write down the likelihood equation for the model. We will write $L(\rho|R)$ for the likelihood of a set of fragment alignments $R$ constructed from $M$ reads. The notation $Pr(trans. = t)$ means ``the probability that a fragment selected at random originates from transcript $t$''. \begin{eqnarray} & & L(\rho|R) = \prod_{r \in R} Pr(rd.\ aln. =r)\\ & = & \prod_{r \in R} \sum_{t \in T} Pr(rd.\ aln. =r|trans. =t)Pr(trans. =t)\\ & = & \prod_{r \in R} \sum_{t \in T} \frac{\rho_t\tilde{l}(t)}{\sum_{u \in T}\rho_u\tilde{l}(u)} Pr(rd.\ aln. = r|trans. =t)\\ & = & \prod_{r \in R} \sum_{t \in T}\frac{\rho_t\tilde{l}(t)}{\sum_{u \in T}\rho_u\tilde{l}(u)} \left(\frac{F(I_t(r))}{l(t)-I_t(r)+1}\right) \\ \label{eq:likerho} & = & \prod_{r \in R} \sum_{t \in T} \alpha_t\left(\frac{F(I_t(r))}{l(t)-I_t(r)+1}\right), \end{eqnarray} where \begin{equation} \alpha_t = \frac{\rho_t\tilde{l}(t)}{\sum_{u \in T}\rho_u\tilde{l}(u)}. \end{equation} Observe that $\alpha_t$ is exactly the probability that a fragment selected at random comes from transcript $t$, and we have that $\sum_{t \in T}\alpha_t = 1$. In light of the probabilistic meaning of the $\alpha=\{\alpha_t\}_{t \in T}$, we refer to them as {\em fragment abundances}. It is evident that the likelihood function is that of a linear model and that the likelihood function is concave (Proposition \ref{prop:linearmodel}) so a numerical method can be used to find the $\alpha$. It is then possible, in principle, to recover the $\rho$ using Lemma \ref{lemma:readstoprobs}. However the number of parameters is in the tens of thousands, and in practice this form of the likelihood function is unwieldy. Instead, we re-write the likelihood utilizing the fact that transcripts in distinct loci do not overlap in genomic location. We first calculate the probability that a fragment originates from a transcript within a given locus $g$: \begin{eqnarray} \beta_g & := & \sum_{t \in g} \alpha_t\\ & = & \frac{\sum_{t \in g} \rho_t \tilde{l}(t)}{\sum_{u \in T} \rho_u \tilde{l}(u)}\\ & = & \frac{\sum_{t \in g} \sigma_g\tau_t \tilde{l}(t)}{\sum_{h \in G} \sum_{u \in h} \sigma_h\tau_u \tilde{l}(u)}\\ & = & \frac{\sigma_g\sum_{t \in g} \tau_t \tilde{l}(t)}{\sum_{h \in G} \sigma_h \sum_{u \in h} \tau_u \tilde{l}(u)}\\ & = & \frac{\sigma_g \tilde{l}(g)}{\sum_{h \in G} \sigma_h \tilde{l}(h)}. \end{eqnarray} Recall that $\sigma_g = \sum_{t \in g} \rho_t$ and that $\tau_t = \frac{\rho_t}{\sigma_g}$ for a locus $g$. Similarly, the probability of selecting a fragment from a single transcript $t$ conditioned on selecting a transcript from the locus $g$ in which $t$ is contained is \begin{equation} \label{eq:gammatau} \gamma_t = \frac{\tau_t \tilde{l}(t)}{\sum_{u \in g} \tau_u \tilde{l}(u)}. \end{equation} The parameters $\gamma=\{\gamma_t\}_{t \in g}$ are conditional fragment abundances, and they are the parameters we estimate from the data in the next Section. Note that for a transcript $t \in g$, $\alpha_t = \beta_g \cdot \gamma_t$ and it is easy to convert between fragment abundances and transcript abundances using Lemma \ref{lemma:readstoprobs}. We denote the fragment counts by $X$; specifically, we denote the number of alignments in locus $g$ by $X_g$. Note that $\sum_{g \in G} X_g = M$. We also use the notation $g_r$ to denote the (unique) locus from which a read alignment $r$ can be obtained. The likelihood function is given by \begin{eqnarray} & & L(\rho|R) = \prod_{r \in R} Pr(rd.\ aln. =r)\\ & = & \prod_{r \in R} \sum_{g \in G} Pr(rd.\ aln. =r|locus=g)Pr(locus=g)\\ & = & \prod_{r \in R} \frac{\sigma_{g_{r}}\tilde{l}(g_{r})}{\sum_{g \in G} \sigma_g\tilde{l}(g)} Pr(rd.\ aln. =r|locus=g_r)\\ & = & \prod_{r \in R} \beta_{g_r} \sum_{t \in g_r}Pr(rd.\ aln. =r|locus=g_{r},trans. = t)Pr(trans. =t|locus=g_r)\\ & = & \prod_{r \in R} \beta_{g_r} \sum_{t \in g_r} \frac{\tau_t\tilde{l}(t)}{\sum_{u \in g_r}\tau_u \tilde{l}(u)} Pr(rd.\ aln. =r|locus=g_{r},trans. = t)\\ & = & \left( \prod_{r \in R} \beta_{g_r} \right) \left( \prod_{r \in R} \sum_{t \in g} \gamma_t \cdot Pr(rd.\ aln. =r|locus=g_r,trans. =t) \right)\\ & = & \left( \prod_{r \in R} \beta_{g_r} \right) \left( \prod_{r \in R} \sum_{t \in g} \gamma_t\cdot \frac{F(I_t(r))}{l(t)-I_t(r)+1}\right)\\ & = & \left( \prod_{g \in G} \beta_g^{X_{g}} \right) \left( \prod_{g \in G} \left( \prod_{r \in R:r \in g} \sum_{t \in g} \gamma_t \cdot \frac{F(I_t(r))}{l(t)-I_t(r)+1}\right) \right). \label{eq:likebest} \end{eqnarray} Explicitly, in terms of the parameters $\rho$, Equation (\ref{eq:likebest}) simplifies to Equation (\ref{eq:likerho}) but we will see in the next section how the maximum likelihood estimates $\hat{\rho}$ are most conveniently obtained by first finding $\hat{\beta}$ and $\hat{\gamma}$ using Equation (\ref{eq:likebest}). We note that it is biologically meaningful to include prior distributions on $\sigma$ and $\tau$ that reflect the inherent stochasticity and resulting variability of transcription in a cell. This will be an interesting direction for further research as more RNA-Seq data (with replicates) becomes available allowing for the determination of biologically meaningful priors. In particular, it seems plausible that specific isoform abundances may vary considerably and randomly within cells from a single tissue and that this may be important in studying differential splicing. We mention to this to clarify that in this paper, the confidence intervals we report represent the variability in the maximum likelihood estimates $\hat{\sigma}_j$ and $\hat{\tau}^k_j$, and are not the variances of prior distributions. \subsubsection{Estimation of parameters} We begin with a discussion of identifiability of our model. Identifiability refers to the injectivity of the model, i.e., \begin{equation} \mbox{if } Pr_{\rho_1}(r) = Pr_{\rho_2}(r) \ \forall r \in R, \ \mbox{ then } \rho_1 = \rho_2. \end{equation} The identifiability of RNA-Seq models was discussed in \cite{Hiller2009}, where a standard analysis for linear models is applied to RNA-Seq (for another related biological example, see \cite{Pe'er2004} which discusses identifiability of haplotypes in mixed populations from genotype data). The results in these papers apply to our model. For completeness we review the conditions for identifiability. Recall that $A_{R,T}$ is the fragment-transcript matrix that specifies which transcripts each fragment is compatible with. The following theorem provides a simple characterization of identifiability: \begin{thm} The RNA-Seq model is identifiable iff $A_{R,T}$ is full rank. \end{thm} Therefore, for a given set of transcripts and a read set $R$, we can test whether the model is identifiable using elementary linear algebra. For the results in this paper, when estimating expression with given annotations, when the model was not identifiable we picked {\em a} maximum likelihood solution, although in principle it is possible to bound the total expression of the locus and/or report identifiability problems to the user. Returning to the likelihood function \begin{equation} \left( \prod_{g \in G} \beta_g^{X_{g}} \right) \left( \prod_{g \in G} \left( \prod_{r \in R:r \in g} \sum_{t \in g} \gamma_t \cdot \frac{F(I_t(r))}{l(t)-I_t(r)+1}\right) \right), \end{equation} we note that both the $\beta$ and $\gamma$ parameters depend on the $\rho$ parameters. However, we will see that if we maximize the $\beta$ separately from the $\gamma$, and also each of the sets $\{\gamma_t:t \in g\}$ separately, then it is always possible to find $\rho$ that match both the maximal $\beta$ and $\gamma$. In other words, the problem of finding $\hat{\rho}$ is equivalent to finding $\hat{\beta}$ that maximizes $ \prod_{g \in G} \beta_g^{X_g}$ and separately, for each locus $g$, the $\hat{\gamma}_t$ that maximize \begin{equation} \prod_{r \in R:r \in g} \sum_{t \in g} \gamma_t \frac{F(I_t(r))}{l(t)-I_t(r)+1}. \end{equation} We begin by solving for the $\hat{\beta}$ and $\hat{\gamma}$ and the variances of the maximum likelihood estimates, and then explain how these are used to report expression levels. We can solve for the $\hat{\gamma}$ using the fact that the model is linear. That is, the probability of each individual read is linear in the read abundances $\gamma_t$. It is a standard result in statistics (see, e.g., Proposition 1.4 in \cite{ASCB2005}) that the log likelihood function of a linear model is concave. Thus, a hill climbing method can be used to find the $\hat{\gamma}$. We used the EM algorithm for this purpose. Rather than using the direct ML estimates, we obtained a regularized estimate by importance sampling from the posterior distribution with a proposal distribution we explain below. The samples were also used to estimate variances for our estimates. It follows from standard MLE asymptotic theory that the $\hat{\gamma}$ are asymptotically multivariate normal with variance-covariance matrix given by the inverse of the observed Fisher information matrix. This matrix is defined as follows: \begin{defn}[Observed Fisher information matrix] The observed Fisher information matrix is the negative of the Hessian of the log likelihood function evaluated at the maximum likelihood estimate. That is, for parameters $\Theta=(\theta_1,\ldots,\theta_n)$, the $n \times n$ matrix is \begin{eqnarray} \mathcal{F}_{k,l}(\hat{\Theta}) & = & - \frac{\partial^2 log(\mathcal{L}(\Theta|R))}{\partial \theta_k \theta_l} |_{\theta=\hat{\theta}}. \end{eqnarray} \end{defn} In our case, considering a single locus $g$, the parameters are $\Theta = (\gamma_{t_1},\ldots,\gamma_{t_{|g|}})$, and as expected from Proposition \ref{prop:linearmodel}: \begin{eqnarray} \label{eq:Fisher} \mathcal{F}_{t_k,t_l}(\hat{\Theta}) & = & \sum_{r \in R:r \in g} \left[ \frac{1}{\left( \sum_{h \in g} \hat{\gamma}_h \frac{F(I_h(r))}{l(h) - I_h(r)+1} \right)^2} \frac{F(I_{t_k}(r)) F(I_{t_l}(r)) }{(l(t_k)-I_{t_k}+1)(l(t_l)-I_{t_l}+1)} \right]. \end{eqnarray} Because some of the transcript abundances may be close to zero, we adopted the Bayesian approach of \cite{Jiang2009} and instead sampled from the joint posterior distribution of $\Theta$ using the proposal distribution consisting of the multivariate normal with mean given by the MLE, and variance-covariance matrix given by the inverse of (\ref{eq:Fisher}). If the Observed Fisher Information Matrix is singular then the user is warned and the confidence intervals of all transcripts are set to $[0,1]$ (meaning that there is no information about relative abundances). The method used for sampling was importance sampling. The samples were used to obtain a maximum-a-posterior estimate for $\hat{\gamma}_t$ for each $t$ and for the variance-covariance matrix which we denote by $\Psi^g$ (where $g \in G$ denotes the locus). Note that $\Psi^g$ is a $|g| \times |g|$ matrix. The covariance between $\hat{\gamma}_{t_k}$ and $\hat{\gamma}_{t_l}$ for $t_k,t_l \in g$ is given by $\Psi^g_{t_k,t_l}$. Turning to the maximum likelihood estimates $\hat{\beta}$, we use the fact that the model is the log-linear. Therefore, \begin{equation} \label{eq:sigmahat} \hat{\beta_g} = \frac{X_{g}}{M}. \end{equation} Viewed as a random variable, the counts $X_{g}$ are approximately Poisson and therefore the variance of the MLE $\hat{\beta}_g$ is approximately $X_{g}$. We note that for the tests in this paper we directly used the total counts $M$ and the proportional counts $X_g$, however it is easy to incorporate recent suggestions for total count normalization, such as \cite{Bullard2010} into {\tt Cufflinks}. The favored units for reporting expression in RNA-Seq studies to date is not using the transcript abundances directly, but rather using a measure abbreviated as FPKM, which means ``expected number of fragments per kilobase of transcript sequence per millions base pairs sequenced''. These units are equivalent to measuring transcript abundances (multiplied by a scalar). The computational advantage of FPKM, is that the normalization constants conveniently simplify some of the formulas for the variances of transcript abundance estimates. For example, the abundance of a transcript $t \in g$ in FPKM units is \begin{equation} \label{eq:FPKM1} \frac{10^6 \cdot 10^3 \cdot \alpha_t}{\tilde{l}(t)} = \frac{10^6 \cdot 10^3 \cdot \beta_g \cdot \gamma_t}{\tilde{l}(t)}. \end{equation} Equation (\ref{eq:FPKM1}) makes it clear that although the abundance of each transcript $t \in g$ in FPKM units is proportional to the transcript abundance $\rho_t$ it is given in terms of the read abundances $\beta_g$ and $\gamma_t$ which are the parameters estimated from the likelihood function. The maximum likelihood estimates of $\beta_g$ and $\gamma_t$ are random variables, and we denote their scaled product (in FPKM units) by $A_t$. That is $Pr(A_t = a)$ is the probability that for a random set of fragment alignments from a sequencing experiment, the maximum likelihood estimate of the transcript abundance for $t$ in FPKM units is $a$. Using the fact that the expectation of a product of independent random variables is the product of the expectations, for a transcript $t \in g$ we have \begin{equation} E[A_t] = \frac{10^9X_{g}\hat{\gamma}_t}{\tilde{l}(t)M}. \end{equation} Given the variance estimates for the $\hat{\gamma}_t$ we turn to the problem of estimating $Var[A_t]$ for a transcript $t \in g$. We use Lemma \ref{lemma:varproduct} to obtain \begin{eqnarray} Var[A_t]& = & \left(\frac{10^9}{\tilde{l}(t)M}\right)^2 \left( \Psi^g_{t,t}X_{g} + \Psi^g_{t,t}X^2_{g} + (\hat{\gamma}_t)^2 X_{g} \right)\\ & = & X_{g}\left(\frac{10^9}{\tilde{l}(t)M)}\right)^2 \left( \Psi^g_{t,t}(1+X_{g}) + (\hat{\gamma}_t)^2\right). \end{eqnarray} This variance calculation can be used to estimate a confidence interval by utilizing the fact \cite{Aroian1978} that when the expectation divided by the standard deviation of at least one of two random variables is large, their product is approximately normal. Next we turn to the problem of estimating expression levels (and variances of these estimates) for groups of transcripts. Let $S \subset T$ be a group of transcripts located in a single locus $g$, e.g. a collection of transcripts sharing a common TSS. The analogy of Equation (\ref{eq:FPKM1}) for the FPKM of the group is \begin{eqnarray} \label{eq:grouphard} & & \frac{10^6 \cdot 10^3 \cdot \beta_g \cdot \left( \sum_{t \in S} \gamma_t\right)}{\tilde{l}(S)}\\ & = & 10^6 \cdot 10^3 \cdot \beta_g \cdot \sum_{t \in S} \frac{\gamma_t}{\tilde{l}(t)}. \label{eq:groupeasy} \end{eqnarray} As before, we denote by $B_S$ the random variables for which $Pr(B_S = b)$ is the probability that for a random set of fragment alignments from a sequencing experiment, the maximum likelihood estimate of the transcript abundance for all the transcripts in $S$ in FPKM units is $b$. We note that the $B_S$ are products and sums of random variables (Equation (\ref{eq:groupeasy})). This makes Equation (\ref{eq:groupeasy}) more useful than the equivalent unsimplified Equation (\ref{eq:grouphard}), especially because $\tilde{l}(S)$ is, in general, a ratio of two random variables. We again use the fact that the expectation of independent random variables is the product of the expectation, in addition to the fact that expectation is a linear operator to conclude that for a group of transcripts $S$, \begin{equation} \label{eq:expectTSS} E[B_S] = \frac{10^9 \cdot X_g \cdot \sum_{t \in S} \frac{\hat{\gamma}_t}{\tilde{l}(t)}}{M}. \end{equation} In order to compute the variance of $B_S$, we first note that \begin{equation} Var\left[\sum_{t \in S} \frac{\hat{\gamma}_t}{\tilde{l}(t)}\right] = \sum_{t \in S}\frac{1}{\tilde{l}(t)^2}\Psi^g_{t,t} + \sum_{t,u \in S} \frac{1}{\tilde{l}(t)\tilde{l}(u)} \Psi^g_{t,u}. \end{equation} Therefore, \begin{eqnarray} & & \quad Var[B_S] \quad = \quad \nonumber \\ & & X_g\left(\frac{10^9}{M}\right)^2\left( \left(1+X_g\right) \left(\sum_{t \in S}\frac{1}{\tilde{l}(t)^2}\Psi^g_{t,t} + \sum_{t,u \in S} \frac{1}{\tilde{l}(t)\tilde{l}(u)} \Psi^g_{t,u}\right) + \left( \sum_{t \in S} \frac{\hat{\gamma}_t}{\tilde{l}(t)} \right)^2 \right). \label{eq:varTSS} \end{eqnarray} We can again estimate a confidence interval by utilizing the fact that $B_S$ is approximately normal \cite{Aroian1978}. \subsection{Transcript assembly} \label{sec:assembly} \subsubsection{Overview} {\tt Cufflinks} takes as input alignments of RNA-Seq fragments to a reference genome and, in the absence of an (optional) user provided annotation, initially assembles transcripts from the alignments. Transcripts in each of the loci are assembled independently. The assembly algorithm is designed to aim for the following: \begin{enumerate} \item Every fragment is consistent with at least one assembled transcript. \item Every transcript is tiled by reads. \item The number of transcripts is the smallest required to satisfy requirement (1). \item The resulting RNA-Seq models (in the sense of Section \ref{sec:abundances}) are identifiable. \end{enumerate} In other words, we seek an assembly that parsimoniously “explains” the fragments from the RNA-Seq experiment; every fragment in the experiment (except those filtered out during a preliminary error-control step) should have come from a {\tt Cufflinks} transcript, and {\tt Cufflinks} should produce as few transcripts as possible with that property. Thus, {\tt Cufflinks} seeks to optimize the criterion suggested in \cite{Xing2004}, however, unlike the method in that paper, {\tt Cufflinks} leverages Dilworth's Theorem \cite{Dilworth1950} to solve the problem by reducing it to a matching problem via the equivalence of Dilworth's and K\"{o}nig's theorems (Theorem \ref{thm:dilko} in Appendix A). Our approach to isoform reconstruction is inspired by a similar approach used for haplotype reconstruction from HIV quasi-species \cite{Eriksson2008}. \subsection{A partial order on fragment alignments} The {\tt Cufflinks} program loads a set of alignments in SAM format sorted by reference position and assembles non-overlapping sets of alignments independently. After filtering out any erroneous spliced alignments or reads from incompletely spliced RNAs, {\tt Cufflinks} constructs a partial order (Definition \ref{def:po}), or equivalently a directed acyclic graph (DAG), with one node for each fragment that in turn consists of an aligned pair of mated reads. First, we note that fragment alignments are of two types: those where reads align in their entirety to the genome, and reads which have a split alignment (due to an implied intron). In the case of single reads, the partial order can be simply constructed by checking the reads for {\em compatibility}. Two reads are {\em compatible} if their overlap contains the exact same implied introns (or none). If two reads are not compatible they are {\em incompatible}. The reads can be partially ordered by defining, for two reads $x,y$, that $x\leq y$ if the starting coordinate of $x$ is at or before the starting coordinate of $y$, and if they are compatible. In the case of paired-end RNA-Seq the situation is more complicated because the unknown sequence between mate pairs. To understand this, we first note that pairs of fragments can still be determined to be incompatible if they cannot have originated from the same transcript. As with single reads, this happens when there is disagreement on implied introns in the overlap. However compatibility is more subtle. We would like to define a pair of fragments $x,y$ to be compatible if they do not overlap, or if every implied intron in one fragment overlaps an identical implied intron in the other fragment. However it is important to note that it may be impossible to determine the compatibility (as defined above) or incompatibility of a pair of fragments. For example, an unknown region internal to a fragment may overlap two different introns (that are incompatible with each other). The fragment may be compatible with one of the introns (and the fragment from which it originates) in which case it is incompatible with the other. Since the opposite situation is also feasible, compatibility (or incompatibility) cannot be assigned. Fragments for which the compatibility/incompatibility cannot be determined with respect to every other fragment are called {\em uncertain}. Finally, two fragments are called {\em nested} if one is contained within the other. \begin{figure}[h] \includegraphics[scale=0.5]{pdfs/compatibility.pdf} \caption[Compatibility and incompatibility of fragments]{Compatibility and incompatibility of fragments. End-reads are solid lines, unknown sequences within fragments are shown by dotted lines and implied introns are dashed lines. The reads in (a) are compatible, whereas the fragments in (b) are incompatible. The fragments in (c) are nested. Fragment $x_4$ in (d) is uncertain, because $y_4$ and $y_5$ are incompatible with each other.} \end{figure} Before constructing a partial order, fragments are extended to include their nested fragments and uncertain fragments are discarded. These discarded fragments are used in the abundance estimation. In theory, this may result in suboptimal (i.e. non-minimal assemblies) but we determined empirically that after assembly uncertain fragments are almost always consistent with one of the transcripts. When they are not, there was no completely tiled transcript that contained them. Thus, we employ a heuristic that substantially speeds up the program, and that works in practice. A partial order $P$ is then constructed from the remaining fragments by declaring that $x \leq y$ whenever the fragment corresponding to $x$ begins at, or before, the location of the fragment corresponding to $y$ and $x$ and $y$ are compatible. In what follows we identify $P$ with its Hasse diagram (or covering relation), equivalently a directed acyclic graph (DAG) that is the transitive reduction. \begin{prop} $P$ is a partial order. \end{prop} {\bf Proof}: The fragments can be totally ordered according to the locations where they begin. It therefore suffices to check that if $x,y,z$ are fragments with $x$ compatible with $y$ and $y$ compatible with $z$ then $x$ is compatible with $z$. Since $x$ is not uncertain, it must be either compatible or incompatible with $z$. The latter case can occur only if $x$ and/or $z$ contain implied introns that overlap and are not identical. Since $y$ is not nested within $z$ and $x$ is not nested within $y$, it must be that $y$ contains an implied intron that is not identical with an implied intron in either $x$ or $z$. Therefore $y$ cannot be compatible with both $x$ and $z$. \qed \subsection{Assembling a parsimonious set of transcripts} In order to assemble a set of transcripts, {\tt Cufflinks} finds a (minimum) partition of $P$ into chains (see Definition \ref{def:po}). A partition of $P$ into chains yields an assembly because every chain is a totally ordered set of compatible fragments $x_1,\ldots,x_l$ and therefore there is a set of overlapping fragments that connects them. By Dilworth's theorem (Theorem \ref{thm:Dilworth}), the problem of finding a minimum partition $P$ into chains is equivalent to finding a maximum antichain in $P$ (an antichain is a set of mutually incompatible fragments). Subsequently, by Theorem \ref{thm:dilko}, the problem of finding a maximum antichain in $P$ can be reduced to finding a maximum matching in a certain bipartite graph that emerges naturally in deducing Dilworth's theorem from K\"{o}nig's theorem \ref{thm:konig}. We call the key bipartite graph the ``reachability'' graph. It is the transitive closure of the DAG, i.e. it is the graph where each fragment $x$ has nodes $L_x$ and $R_x$ in the left and right partitions of the reachability graph respectively, and where there is an edge between $L_x$ and $R_y$ when $x \leq y$ in $P$. The maximum matching problem is a classic problem that admits a polynomial time algorithm. The Hopcroft-Karp algorithm \cite{Hopcroft1973} has a run time of $O(\sqrt{V}E)$ where in our case $V$ is the number of fragments and $E$ depends on the extent of overlap, but is bounded by a constant times the coverage depth. We note that our parsimony approach to assembly therefore has a better complexity than the $O(V^3)$ PASA algorithm \cite{Haas2003}. The minimum cardinality chain decomposition computed using the approach above may not be unique. For example, a locus may contain two putative distinct initial exons (defined by overlapping incompatible fragments), and one of two distinct terminal and a constitutive exon in between that is longer than any read or insert in the RNA-Seq experiment. In such a case, the parsimonious assembly will consist of two transcripts, but there are four possible solutions that are all minimal. In order to ``phase'' distant exons, we leverage the fact that abundance inhomogeneities can link distant exons via their coverage. We therefore weight the edges of the bipartite reachability graph based on the percent-spliced-in metric introduced by Wang \emph{et al.} in \cite{Wang2008}. In our setting, the percent-spliced-in $\psi_x$ for an alignment $x$ is computed by counting the alignments overlapping $x$ in the genome that are compatible with $x$ and dividing by the total number of alignments that overlap $x$, and normalizing for the length of the $x$. The cost $C(y,z)$ assigned to an edge between alignments $y$ and $z$ reflects the belief that they originate from different transcripts: \begin{equation} C(y,z) = -\log(1 - |\psi_y - \psi_z|). \label{eq:match_cost} \end{equation} Rather than using the Hopcroft-Karp algorithm, a modified version of the {\tt LEMON} \cite{LEMON} and {\tt Boost} \cite{Boost} graph libraries are used to compute a {\em min-cost} maximum cardinality matching on the bipartite compatibility graph. Even with the presence of weighted edges, our algorithm is very fast. The best known algorithm for weighted matching is $O(V^2logV+VE)$. Because we isolated total RNA, we expected that a small fraction of our reads would come from the intronic regions of incompletely processed primary transcripts. Moreover, transcribed repetitive elements and low-complexity sequence result in ``shadow'' transfrags that we wished to discard as artifacts. Thus, {\tt Cufflinks} heuristically identifies artifact transfrags and suppresses them in its output. We also filter extremely low-abundance minor isoforms of alternatively spliced genes, using the model described in Section \ref {abundances} as a means of reducing the variance of estimates for more abundant transcripts. A transcript $x$ meeting any of the following criteria is suppressed: \begin{enumerate} \item $x$ aligns to the genome entirely within an intronic region of the alignment for a transcript $y$, and the abundance of $x$ is less than 15\% of $y$'s abundance. \item $x$ is supported by only a single fragment alignment to the genome. \item More than 75\% of the fragment alignments supporting $x$, are mappable to multiple genomic loci. \item $x$ is an isoform of an alternatively spliced gene, and has an estimated abundance less than 5\% of the major isoform of the gene. \end{enumerate} Prior to transcript assembly, {\tt Cufflinks} also filters out some of the alignments for fragments that are likely to originate from incompletely spliced nuclear RNA, as these can reduce the accuracy abundance estimates for fully spliced mRNAs. These filters and the output filters above are detailed in the source file \verb!filters.cpp! of the source code for {\tt Cufflinks}. In the overview of this Section, we mentioned that our assembly algorithm has the property that the resulting models are identifiable. This is a convenient property that emerges naturally from the parsimony criterion for a ``minimal explanation'' of the fragment alignments. Formally, it is a corollary of Dilworth's theorem: \begin{prop} The assembly produced by the {\tt Cufflinks} algorithm always results in an identifiable RNA-Seq model. \end{prop} {\bf Proof}: By Dilworth's theorem, the minimum chain decomposition (assembly) we obtain has the same size as the maximum antichain in the partially ordered set we construct from the reads. An antichain consists of reads that are pairwise incompatible, and therefore those reads must form a permutation sub-matrix in the fragment-transcript matrix $A_{R,T}$ with columns corresponding to the transcripts in a locus, and with rows corresponding to the fragments in the antichain. The matrix $A_{R,T}$ therefore contains permutation sub-matrices that together span all the columns, and the matrix is full-rank. \subsection{Assessment of assembly quality} To compare {\tt Cufflinks} transfrags against annotated transcriptomes, and also to find transfrags common to multiple assemblies, we developed a tool called {\tt Cuffcompare} that builds structural equivalence classes of transcripts. We ran {\tt Cuffcompare} on each the assembly from each time point against the combined annotated transcriptomes of the {UCSC known genes}, {\tt Ensembl}, and {\tt Vega}. Because of the stochastic nature of sequencing, \emph{ab initio} assembly of the same transcript in two different samples may result in transfrags of slightly different lengths. A {\tt Cufflinks} transfrag was considered a complete match when there was a transcript with an identical chain of introns in the combined annotation. When no complete match is found between a {\tt Cufflinks} transfrag and the transcripts in the combined annotation, {\tt Cuffcompare} determines and reports if another substantial relationship exists with any of the annotation transcripts that can be found in or around the same genomic locus. For example, when all the introns of a transfrag match perfectly a part of the intron chain (sub-chain) of an annotation transcript, a ``containment'' relationship is reported. For single-exon transfrags, containment is also reported when the exon appears fully overlapped by any of the exons of an annotation transcript. If there is no perfect match for the intron chain of a transfrag but only some exons overlap and there is at least one intron-exon junction match, {\tt Cuffcompare} classifies the transfrag as a putative ``novel'' isoform of an annotated gene. When a transfrag is unspliced (single-exon) and it overlaps the intronic genomic space of a reference annotation transcript, the transfrag is classified as potential pre-mRNA fragment. Finally, when no other relationship is found between a {\tt Cufflinks} transfrag and an annotation transcript, {\tt Cuffcompare} can check the repeat content of the transfrag's genomic region (assuming the soft-masked genomic sequence was also provided) and it would classify the transfrag as ``repeat'' if most of its bases are found to be repeat-masked. When provided multiple time point assemblies, {\tt Cuffcompare} matches transcripts \subsubsection{Testing for changes in absolute expression} Between any two consecutive time points, we tested whether a transcript was significantly (after FDR control \cite{Benjamini1995}) up or down regulated with respect to the null hypothesis of no change, with variability in expression due solely to the uncertainties resulting from our abundance estimation procedure. This was done using the following testing procedure for absolute differential expression: We employed the standard method used in microarray-based expression analysis and proposed for RNA-Seq in \cite{Bullard2010}, which is to compute the logarithm of the ratio of intensities (in our case FPKM), and to then use the delta method to estimate the variance of the log odds. We describe this for testing differential expression of individual transcripts and also groups of transcripts (e.g. grouped by TSS). We recall that the MLE FPKM for a transcript $t$ in a locus $g$ is given by \begin{equation} \frac{10^9X_g\hat{\gamma}_t}{\tilde{l}(t)M}. \end{equation} Given two different experiments resulting in $X^a_g,M^a$ and $X^b_g,M^b$ respectively, as well as $\hat{\gamma}^a_t$ and $\hat{\gamma}^b_t$, we would like to test the significance of departures from unity of the ratio of MLE FPKMS, i.e. \begin{eqnarray} & & \left(\frac{10^9X^a_g\hat{\gamma}^a_t}{\tilde{l}(t)M^a}\right) / \left(\frac{10^9X^b_g\hat{\gamma}^b_t}{\tilde{l}(t)M^b}\right)\\ & = & \frac{X_g^a\hat{\gamma}^a_tM^b}{X_g^b \hat{\gamma}^b_tM^a}. \end{eqnarray} This can be turned into a test statistic that is approximately normal by taking the logarithm, and normalizing by the variance. We recall that using the delta method, if $X$ is a random variable then $Var[log(X)] \approx \frac{Var[X]}{E[X]^2}$. Therefore, our test statistic is \begin{equation} \frac{log(X^a_g)+log(\hat{\gamma}^a_t)+log(M^b)-log(X^b_g)-log(\hat{\gamma}^b_t)-log(M^a)} { \sqrt{\frac{\left( \Psi^{g,a}_{t,t}(1+X^a_{g}) + (\hat{\gamma}^a_t)^2\right)}{X^a_g \left(\hat{\gamma}^a_t \right)^2}+ \frac{\left( \Psi^{g,b}_{t,t}(1+X^b_{g}) + (\hat{\gamma}^b_t)^2\right)}{X^b_{g}\left( \hat{\gamma}^b_t\right)^2} } }. \end{equation} In order to test for differential expression of a group of transcripts, we replace the numerator and denominator above by those from Equations (\ref{eq:expectTSS}) and (\ref{eq:varTSS}). It is has been noted that the power of differential expression tests in RNA-Seq depend on the length of the transcripts being tested, because longer transcripts accumulate more reads \cite{Oshlack2009}. This means that the results we report are biased towards discovering longer differentially expressed transcripts and genes. \subsection{Quantifying transcriptional and post-transcriptional overloading} In order to infer the extent of differential promoter usage, we decided to measure changes in relative abundances of primary transcripts of single genes. Similarly, we investigated changes in relative abundances of transcripts grouped by TSS in order to infer differential splicing. These inferences required two ingredients: \begin{enumerate} \item A metric on probability distributions (derived from relative abundances). \item A test statistic for assessing significant changes in differential promoter usage and splicing as measured using the metric referred to above. \end{enumerate} In order to address the first requirement, namely a metric on probability distributions, we turned to an entropy-based metric. This was motivated by the methods in \cite{Ritchie2008} where tests for differences in relative isoform abundances were performed to distinguish cancer cells from normal cells. We extend this approach to be able to test for relative isoform abundance changes among multiple experiments in RNA-Seq. \begin{defn}[Entropy] The entropy of a discrete probability distribution $p=(p_1,\ldots,p_n)$ ($0 \leq p_i \leq 1$ and $\sum_{i=1}^n p_i = 1$) is \begin{equation} H(p) = -\sum_{i=1}^n p_i log p_i. \end{equation} If $p_i=0$ for some $i$ the value of $p_i log p_i$ is taken to be $0$. \end{defn} \begin{defn}[The Jensen-Shannon divergence] The Jensen-Shannon divergence of $m$ discrete probability distributions $p^1,\ldots,p^m$ is defined to be: \begin{equation} JS(p^1,\ldots,p^m) = H\left(\frac{p^1 + \cdots + p^m}{m}\right) - \frac{\sum_{j=1}^m H(p^j)}{m}. \end{equation} In other words, the Jensen-Shannon divergence of a set of probability distributions is the entropy of their average minus the average of their entropies. \end{defn} In the case where $m=2$, we remark that the Jensen-Shannon divergence can also be described in terms of the Kullback-Leibler divergence of two discrete probability distributions. If we denote Kullback-Leibler divergence by \begin{equation} D(p^1\|p^2) = \sum_i p^1_i log \frac{p^1_i}{p^2_i}, \end{equation} then \begin{equation} JS(p^1,p^2) = \frac{1}{2}D(p^1\|m)+\frac{1}{2}D(p^2\|m) \end{equation} where $m=\frac{1}{2}(p^1+p^2)$. In other words the Jensen-Shannon divergence is a symmetrized variant of the Kullback-Leibler divergence. The Jensen-Shannon divergence has a number of useful properties: for example it is symmetric and non-negative. However it is {\em not} a metric. The following theorem shows how to construct a metric from the Jensen-Shannon divergence: \begin{thm}[Fuglede and Tops{\o}e 2004 \cite{Fuglede2004}] The square root of the Jensen-Shannon divergence is a metric. \end{thm} The proof of this result is based on a harmonic analysis argument that is the basis for the remark in the main paper that ``transcript abundances move in time along a logarithmic spiral in Hilbert space''. We therefore call the square root of the Jensen-Shannon divergence the {\em Jensen-Shannon metric}. We employed this metric in order to quantify relative changes in expression in (groups of) transcripts. In order to test for significance, we introduce a bit of notation. Suppose that $S$ is a collection of transcripts (for example, they may share a common TSS). We define \begin{equation} \kappa_t = \frac{ \frac{\gamma_t}{\tilde{l}(t)}}{\sum_{u \in S} \frac{\gamma_u}{\tilde{l}(u)}} \end{equation} to be the proportion of transcript $t$ among all the transcripts in a group $S$. We let $Z=\sum_{u \in S} \hat{\gamma}_u / \tilde{l}(u)$ so that $\hat{\kappa}_t = \frac{\gamma_t}{\tilde{l}(t)Z}$. We therefore have that \begin{eqnarray} \label{eq:variancekappa1} Var[\hat{\kappa}_t] & = &\frac{Var[\hat{\gamma}_t]}{\tilde{l}(t)^2Z^2}, \\ Cov[\hat{\kappa}_t,\hat{\kappa}_u] & = & \frac{Cov[\hat{\gamma}_t,\hat{\gamma}_u]}{\tilde{l}(t)\tilde{l}(u)Z^2}.\label{eq:variancekappa2} \end{eqnarray} Our test statistic for divergent relative expression was the Jensen-Shannon metric. The test could be applied to multiple time points simultaneously, but we focused on pairwise tests (involving consecutive time points). Under the null hypothesis of no change in relative expression, the Jensen-Shannon metric should be zero. We tested for this using a one-sided $t$-test, based on an asymptotic derivation of the distribution of the Jensen-Shannon metric under the null hypothesis. This asymptotic distribution is normal by applying the delta method approximation, which involves computing the linear component of the Taylor expansion of the variance of $\sqrt{JS}$. In order to simplify notation, we let $f(p^1,\ldots,p^m)$ be the Jensen-Shannon metric for $m$ probability distributions $p^1,\ldots,p^m$. \begin{lemma} The partial derivatives of the Jensen-Shannon metric are give by \begin{equation} \frac{\partial f}{\partial p^k_l} = \frac{1}{2m\sqrt{f(p^1,\ldots,p^m)}} log \left( \frac{p^k_l}{\frac{1}{m} \sum_{j=1}^m p_l^j} \right). \end{equation} \end{lemma} Let $\hat{\kappa}^1,\ldots,\hat{\kappa}^m$ denote $m$ probability distributions on the set of transcripts $S$, for example the MLE for the transcript abundances in a time course. Then from the delta method we have that $\sqrt{JS(\hat{\kappa}^1,\ldots,\hat{\kappa}^m)}$ is approximately normally distributed with variance given by \begin{equation} Var[\sqrt{JS(\hat{\kappa}^1,\ldots,\hat{\kappa}^m)}] \approx (\bigtriangledown f)^T \Sigma (\bigtriangledown f), \end{equation} where $\Sigma$ is the variance-covariance matrix for the $\kappa^1,\ldots,\kappa^m$, i.e., it is a block diagonal matrix where the $i$th block is the variance-covariance matrix for the $\kappa^i_t$ given by Equations (\ref{eq:variancekappa1},\ref{eq:variancekappa2}). There are two biologically meaningful groupings of transcripts whose relative abundances are interesting to track in a time course. Transcripts that share a TSS are likely to be regulated by the same promoter, and therefore tracking the change in relative abundances of groups of transcripts sharing a TSS may reveal how transcriptional regulation is affecting expression over time. Similarly, transcripts that share a TSS and exhibit changes in expression relative to each other are likely to be affected by splicing or other post-transcriptional regulation. We therefore grouped transcripts by TSS and compared relative abundance changes within and between groups. We define ``overloading'' to be a significant change in relative abundances for a set of transcripts (as determined by the Jensen-Shannon metric, see below). The term is intended to generalize the simple notion of ``isoform switching'' that is well-defined in the case of two transcripts, to multiple transcripts. It is complementary to absolute differential changes in expression: the overall expression of a gene may remain constant while individual transcripts change drastically in relative abundances resulting in overloading. The term is borrowed from computer science, where in some statically-typed programming languages, a function may be used in multiple, specialized instances via ``method overloading''. We tested for overloaded genes by performing a one-sided $t$-test based on the asymptotics of the Jensen-Shannon metric under the null hypothesis of no change in relative abundnaces of isoforms (either grouped by shared TSS for for post-transcriptional overloading, or by comparison of groups of isoforms with shared TSS for transcriptional overloading). Type I errors were controlled with the Benjamini-Hochberg \cite{Benjamini1995} correction for multiple testing. A selection of overloaded genes are displayed in Supplemental Figs. \ref{splice_overloaded} and \ref{promoter_overloaded}. \newpage \begin{figure}[!ht] \includegraphics{pdfs/splice_overloaded} \caption[Selected genes with post-transcriptional overloading]{Selected genes with post-transcriptional overloading. Trajectories indicate the expression of individual isoforms in FPKM ($y$ axis) over time in hours ($x$ axis). Dashed isoforms have not been previously annotated. Isoform trajectories are colored by TSS, so isoforms with the same color presumably share a common promoter and are processed from the same primary transcript. It is evident that total gene expression may remain constant during isoforms switching (Eya3) while in other cases changes in relative abundance are accompanied by changes in absolute expression. The Jensen-Shannon metric generalizes the notion of ``isoform switching'' and is useful in cases with multiple isoforms (e.g. Ddx17). \label{splice_overloaded}} \end{figure} \begin{figure}[!ht] \includegraphics{pdfs/promoter_overloaded} \caption[Selected genes with transcriptional overloading]{Selected genes with transcriptional overloading. Trajectories indicate the expression of individual isoforms in FPKM (y axis) over time in hours (x axis). Dashed isoforms have not been previously annotated. Isoform trajectories are colored by TSS, so that isoforms with different colors presumably vary in their promoter and are processed from different primary transcripts. \label{promoter_overloaded}} \end{figure} We can visualize overloading and expression dynamics with a plot that superimposes transcriptional and post-transcriptional overloading and gene-level expression over the time course. We refer to these as ``Minard plots'', after Charles Joseph Minard's famous depiction of the advance and retreat of Napoleon's armies in the campaign against Russia in 1812 \cite{Tufte2001}. Minard made use of multiple visual cues to display numerous varying quantities in one diagram. An example of a Minard plot for the gene Myc is shown in Figure 3c, and others are given in Appendix B. The dotted line indicates gene-level FPKM, with measured FPKM indicated by black circles. Grey circles indicate the arithmetic mean of gene-level FPKM between consecutive measured time points, interpolating FPKM at intermediate time points. The total gene expression overloading is visualized as a swatch centered around the interpolated expression curve. The width of the swatch encodes the amount of expression overloading between successive time points. The color of the swatch indicates the relative contributions of transcriptional and post-transcriptional expression overloading. Some genes, such as tropomyosin I and II, feature a single primary transcript, and so all overloading is by definition post-transcriptional. Others, like Fhl3, have two primary transcripts, but only a single isoform arises from each, so all overloading is transcriptional. Genes with multiple primary transcripts, one or more of which are alternatively spliced, such as Myc or RTN4, display both forms. \subsection{The {\tt Cufflinks} software} The transcript assembly and abundance estimation algorithms are implemented in freely available open source software called {\tt Cufflinks} that is available from \newline {\tt http://cufflinks.cbcb.umd.edu/} \newline Furthermore methods for comparing annotations across time points, and for performing the differential expression, promoter usage and splicing tests are implemented in the companion programs {\tt Cuffdiff} and {\tt Cuffcompare}. Instructions on how to install and run the software are provided on the website. The input to {\tt Cufflinks} consists of fragment alignments in the SAM format \cite{Li2009a}. These may consist of either single fragment alignments, or alignments of mate-pairs (paired-end reads produce better assemblies and more accurate abundance estimates than single reads). {\tt Cufflinks} will assemble the transcripts using the algorithm in Section \ref{sec:assembly}, and transcript abundances will be estimated using the model in Section \ref{sec:abundances}. Transcript coordinates and abundances are reported in the Gene Transfer Format (GTF). User supplied annotations may be provided to {\tt Cufflinks} (optional input) in which case they form the basis for the transcript abundance estimation. Some of the algorithms here rely on sufficient depth of sequencing in order to produce reliable output. {\tt Cufflinks} determines that depth is sufficient where possible to check that required assumptions hold. For example, in loci where one or more isoforms have extremely low relative expression, the observed Fisher Information Matrix may not be positive definite after rounding errors. In this case, it is not possible to produce a reliable variance-covariance matrix for isoform fragment abundances. {\tt Cufflinks} will report a numerical exception in this and similar cases. When an exception is reported, the confidence intervals for the isoforms' abundances will be set from 0 FPKM to the FPKM for the whole gene. If such an exception is generated during a {\tt Cuffdiff} run, no differential analysis involving the problematic sample will be performed on that locus. \newpage \section{Appendix A: Lemmas and Theorems} The following elementary/classical results are required for our methods and we include them so that the supplement is self-contained. \begin{lemma} \label{lemma:varsum} Let $X_1,\ldots,X_n$ be random variables and $a_1,\ldots,a_n$ real numbers with $Y=\sum_{i=1}^na_iX_i$. Then \begin{equation} Var[Y] = \sum_{i=1}^n a_i^2Var[X_i]+2\sum_{i<j} a_ia_j Cov[X_i,X_j]. \end{equation} \end{lemma} \begin{lemma}[Taylor Series] If $X$ and $Y$ are random variables then \begin{eqnarray} Var[f(X,Y)] & \approx & \left(\frac{\partial f}{\partial X}(E[X],E[Y])\right)^2Var[X] \nonumber \\ & &+2\frac{\partial f}{\partial X}(E[X],E[Y])\frac{\partial f}{\partial Y}(E[X],E[Y])Cov[X,Y] \nonumber \\ & & +\left( \frac{\partial f}{\partial Y}(E[X],E[Y])\right)^2 Var[Y]. \end{eqnarray} \end{lemma} \begin{cor} If $X$ and $Y$ are independent then \begin{eqnarray} Var\left[log\left(\frac{X}{Y}\right)\right] & \approx & \frac{V[X]}{E[X]^2} + \frac{V[Y]}{E[Y]^2}. \end{eqnarray} \end{cor} \begin{cor} \label{lemma:varproduct} If $X$ and $Y$ are independent random variables then \begin{equation} Var[XY] = Var[X]Var[Y]+E[X]^2Var[Y]+E[Y]^2Var[X]. \end{equation} \end{cor} The above result is exact using the 2nd order Taylor expansion (higher derivatives vanish). \begin{lemma}[\cite{Li2009b}] \label{lemma:readstoprobs} Let $a_1,\ldots,a_n,w_1,\ldots,w_n$ be real numbers satisfying: $w_i \neq 0$ and $0 \leq a_i \leq 1$ for all $i$, $\sum_{i=1}^n a_i = 1$ and $\sum_{i=1}^na_iw_i \neq 0$. Let $ b_j = \frac{a_jw_j}{\sum_{i=1}^n a_iw_i}$. Then $a_j = \frac{b_j\frac{1}{w_j}}{\sum_{i=1}^n b_i\frac{1}{w_i}}$. \end{lemma} {\bf Proof}: \begin{eqnarray} b_j & = & \frac{a_jw_j}{\sum_{i=1}^n a_iw_i} \\ \Rightarrow \, \sum_{k=1}^n \frac{b_k}{w_k} & = & \sum_{k=1}^n \frac{a_k}{\sum_{i=1}^na_iw_i}\\ & = & \frac{1}{\sum_{i=1}^n a_iw_i}\\ & = & \frac{b_j}{a_jw_j}\\ \Rightarrow \, a_j & = & \frac{b_j\frac{1}{w_j}}{\sum_{i=1}^n b_i \frac{1}{w_i}}. \end{eqnarray} \qed \begin{prop}[\cite{ASCB2005}] \label{prop:linearmodel} Let $f_i(\theta) = \sum_{j=1}^d a_{ij}\theta_j + b_i$ ($1 \leq i \leq m$) describe a linear statistical model with $a_{ij} \geq$ for all $i,j$. That is, $\sum_{i=1}^m f_i(\theta) = 1$. If $u_i \geq 0$ for all $i$ then the log likelihood function \begin{equation} l(\theta) = \sum_{i=1}^m u_i log(f_i(\theta)) \end{equation} is concave. \end{prop} {\bf Proof}: It is easy to see that \begin{equation} \left( \frac{\partial^2 l}{\partial \theta_j \partial \theta_k} \right) = -A^Tdiag\left( \frac{u_1}{f_1(\theta)^2},\ldots,\frac{u_m}{f_m(\theta)^2}\right) A, \end{equation} where $A$ is the $m \times d$ matrix whose entry in row $i$ and column $j$ equals $a_{ij}$. Therefore the Hessian is a symmetric matrix with non-positive eigenvalues, and is therefore negative semi-definite. \qed \begin{defn} \label{def:po} A partially ordered set is a set $S$ with a binary relation $\leq$ satisfying: \begin{enumerate} \item $x \leq x$ for all $x \in S$, \item If $x \leq y$ and $y \leq z$ then $x \leq z$, \item If $x \leq y$ and $y \leq x$ then $x=y$. \end{enumerate} A {\em chain} is a set of elements in $C \subseteq S$ such that for every $x,y \in C$ either $x \leq y$ or $y \leq x$. An {\em antichain} is a set of elements that are pairwise incompatible. \end{defn} Partially ordered sets are equivalent to directed acyclic graphs (DAGs). The following min-max theorems relate chain partitions to antichains and are special cases of linear-programming duality. More details and complete proofs can be found in \cite{Lovasz2009}. \begin{thm}[Dilworth's theorem] \label{thm:Dilworth} Let $P$ be a finite partially ordered set. The maximum number of elements in any antichain of $P$ equals the minimum number of chains in any partition of $P$ into chains. \end{thm} \begin{thm}[K\"{o}nig's theorem] \label{thm:konig} In a bipartite graph, the number of edges in a maximum matching equals the number of vertices in a minimum vertex cover. \end{thm} \begin{thm} \label{thm:dilko} Dilworth's theorem is equivalent to K\"{o}nig's theorem. \end{thm} {\bf Proof}: We first show that Dilworth's theorem follows from K\"{o}nig's theorem. Let $P$ be a partially ordered set with $n$ elements. We define a bipartite graph $G=(U,V,E)$ where $U=V=P$, i.e. each partition in the bipartite graph is equally to $P$. Two nodes $u,v$ form an edge $(u,v) \in E$ in the graph $G$ iff $u<v$ in $P$. By K\"{o}nig's theorem there exist both a matching $M$ and a a vertex cover $C$ in $G$ of the same cardinality. Let $T \subset S$ be the set of elements not contained in $C$. Note that $T$ is an antichain in $P$. We now form a partition $W$ of $P$ into chains by declaring $u$ and $v$ to be in the same chain whenever there is an edge $(u,v) \in M$. Since $C$ and $M$ have the same size, it follows that $T$ and $W$ have the same size. To deduce K\"{o}nig's theorem from Dilworth's theorem, we begin with a bipartite graph $G=(U,V,E)$ and form a partial order $P$ on the vertices of $G$ by defining $u<v$ when $u \in U, v \in V$ and $(u,v) \in E$. By Dilworth's theorem, there exists an antichain of $P$ and a partition into chains of the same size. The non-trivial chains in $P$ form a matching in the graph. Similarly, the complement of the vertices corresponding to the anti-chain in $P$ is a vertex cover of $G$ with the same cardinality as the matching. \qed \begin{figure}[!ht] \includegraphics[scale=0.8]{pdfs/Dilworth_Konig} %\caption[Equivalence of Dilworth's and K\"{o}nig's theorems]{ \end{figure} The equivalence of Dilworth's and K\"{o}nig's theorems is depicted above. The partially ordered set with 8 elements on the left is partitioned into 3 chains. This is the size of a minimum partition into chains, and is equal to the maximum size of an antichain (Dilworth's theorem). The antichain is shown with double circles. On the right, the reachability graph constructed from the partially ordered set on the left is shown. The maximum matching corresponding to the chain partition consists of 5 edges and is equal in size to the number of vertices in a minimum vertex cover (K\"{o}nig's theorem). The vertex cover is shown with double circles. Note that 8=3+5. \newpage \bibliographystyle{amsplain} \bibliography{cufflinks} \end{document} % long read length is required for uniquely determining genomic origin of fragments, but its fragment length that is critical for assignment of fragments to transcripts. % The length of a set of transcripts depends on their abundances % single read sequencing prevents the correct normalization for fragment sizes in the length.
\documentclass[11pt]{article} \usepackage{reduce} \usepackage{hyperref} \title{{\tt SPECFN}: Special Functions Package for REDUCE} \date{} \author{Chris Cannam, et. al.\\[0.05in] Konrad--Zuse--Zentrum f\"ur Informationstechnik Berlin \\ Takustrasse 7\\ D--14195 Berlin -- Dahlem \\ Federal Republic of Germany \\[0.05in] E--mail: neun@zib.de \\[0.05in] Version 2.5, October 1998} \begin{document} \maketitle \index{SPECFN package} \section{Introduction} This package provides the 'common' special functions for REDUCE. The names of the operators and implementation details can be found in this document. Due to the enormous number of special functions a package for special functions is never complete. Several users pointed out that important classes of special functions were missing in the first version. These comments and other hints from a number of contributors and users were very helpful. The first version of this package was developed while the author worked as a student exchange grantee at ZIB Berlin in 1992/93. The package is maintained by ZIB Berlin after the author left the ZIB. Therefore, please direct comments, hints and bug reports etc. to {\tt neun@zib.de}. Numerous contributions have been integrated after the release with version 3.5 of REDUCE. This package is designed to provide algebraic and numeric manipulations of several common special functions, namely: \begin{itemize} \item Bernoulli numbers and Polynomials; \item Euler numbers and Polynomials; \item Fibonacci numbers and Polynomials; \item Stirling numbers; \item Binomial Coefficients; \item Pochhammer notation; \item The Gamma function; \item The psi function and its derivatives; \item The Riemann Zeta function; \item The Bessel functions J and Y of the first and second kinds; \item The modified Bessel functions I and K; \item The Hankel functions H1 and H2; \item The Kummer hypergeometric functions M and U; \item The Beta function, and Struve, Lommel and Whittaker functions; \item The Airy funcions; \item The Exponential Integral, the Sine and Cosine Integrals; \item The Hyperbolic Sine and Cosine Integrals; \item The Fresnel Integrals and the Error function; \item The Dilog function; \item The Polylogarithm and Lerch Phi function; \item Hermite Polynomials; \item Jacobi Polynomials; \item Legendre Polynomials; \item Associated Legendre Functions (Spherical and Solid Harmonics) \item Laguerre Polynomials; \item Chebyshev Polynomials; \item Gegenbauer Polynomials; \item Lambert's $\omega$ function; \item (Jacobi's) Elliptic Functions; \item Elliptic Integrals; \item 3j and 6j symbols , Clebsch-Gordan coefficients; \item and some well-known constants. \end{itemize} All algorithms whose sources are uncredited are culled from series or expressions found in the Dover Handbook of Mathematical Functions\cite{Abramowitz:72}. There is a nice collection of plot calls for special functions in the file \$reduce/plot/specplot.tst. These examples will reproduce a number of well-known pictures from \cite{Abramowitz:72}. \section{Compatibility with earlier \REDUCE\ versions} For {PSL} versions, this package is intended to be used with the new \REDUCE\ bigfloat mechanisms which is distributed together with REDUCE 3.5 and later versions. The package does work with the earlier bigfloat implementations, but in order to ensure that it works efficiently with the new versions, it has not been optimized for the old. \section{Simplification and Approximation} All of the operators supported by this package have certain algebraic simplification rules to handle special cases, poles, derivatives and so on. Such rules are applied whenever they are appropriate. However, if the {\tt ROUNDED} switch is on, numeric evaluation is also carried out. Unless otherwise stated below, the result of an application of a special function operator to real or complex numeric arguments in rounded mode will be approximated numerically whenever it is possible to do so. All approximations are to the current precision. Most algebraic simplifications within the special function package are defined in the form of a \REDUCE\ ruleset. Therefore, in order to get a quick insight into the simplification rules one can use the ShowRules operator, e.g.\\ \begin{verbatim} ShowRules BesselI; 1 ~z - ~z {besseli(~n,~z) => ---------------*(e - e ) sqrt(pi*2*~z) 1 when numberp(~n) and ~n=---, 2 1 ~z - ~z besseli(~n,~z) => ---------------*(e + e ) sqrt(pi*2*~z) 1 when numberp(~n) and ~n= - ---, 2 besseli(~n,~z) => 0 when numberp(~z) and ~z=0 and numberp(~n) and ~n neq 0, besseli(~n,~z) => besseli( - ~n,~z) when numberp(~n) and impart(~n)=0 and ~n=floor(~n) and ~n<0, besseli(~n,~z) => do*i(~n,~z) when numberp(~n) and numberp(~z) and *rounded, df(besseli(~n,~z),~z) besseli(~n - 1,~z) + besseli(~n + 1,~z) => -----------------------------------------, 2 df(besseli(~n,~z),~z) => besseli(1,~z) when numberp(~n) and ~n=0} \end{verbatim} Several \REDUCE\ packages (such as Sum or Limits) obtain different (hopefully better) results for the algebraic simplifications when the SPECFN package is loaded, because the later package contains some information which may be useful and directly applicable for other packages, e.g.: \begin{verbatim} sum(1/k^s,k,1,infinity); % will be evaluated to zeta(s) \end{verbatim} \ttindex{savesfs} A record is kept of all values previously approximated, so that should a value be required which has already been computed to the current precision or greater, it can be simply looked up. This can result in some storage overheads, particularly if many values are computed which will not be needed again. In this case, the switch {\tt savesfs} may be turned off in order to inhibit the storage of approximated values. The switch is on by default. \section{Constants} \ttindex{Euler\_Gamma}\ttindex{Khinchin}\ttindex{Golden\_Ratio} \ttindex{Catalan} Some well-known constants are defined in the special function package. Important properties of these constants which can be used to define them are also known. Numerical values are computed at arbitrary precision if the switch ROUNDED is on. \begin{itemize} \item Euler\_Gamma : Euler's constant, also available as -$\psi(1)$; \item Catalan : Catalan's constant; \item Khinchin : Khinchin's constant , defined in \cite{Khinchin:64}. (takes a lot of time to compute); \item Golden\_Ratio : $\frac{1 + \sqrt{5}}{2}$ \end{itemize} \section{Bernoulli Numbers and Euler Numbers} \ttindex{Bernoulli}\index{Bernoulli numbers} \ttindex{Euler}\index{Euler numbers} The unary operator {\tt Bernoulli} provides notation and computation for Bernoulli numbers. {\tt Bernoulli(n)} evaluates to the $n$th Bernoulli number; all of the odd Bernoulli numbers, except {\tt Bernoulli(1)}, are zero. The algorithms are based upon those by Herbert Wilf, presented by Sandra Fillebrown \cite{Fillebrown:92}. If the {\tt ROUNDED} switch is off, the algorithms are exactly those; if it is on, some further rounding may be done to prevent computation of redundant digits. Hence, these functions are particularly fast when used to approximate the Bernoulli numbers in rounded mode. Euler numbers are computed by the unary operator Euler, which return the nth Euler number. The computation is derived directly from Pascal's triangle of binomial coefficients. \section{Fibonacci Numbers and Fibonacci Polynomials} \ttindex{Fibonacci}\index{Fibonacci numbers} \ttindex{Fibonacci Polynomials} The unary operator {\tt Fibonacci} provides notation and computation for Fibonacci numbers. {\tt Fibonacci(n)} evaluates to the $n$th Fibonacci number. If n is a positive or negative integer, it will be evaluated following the definition: $F_0 = 0 ; F_1 = 1 ; F_n = F_{n-1} + F_{n-2} $ Fibonacci Polynomials are computed by the binary operator FibonacciP. FibonacciP(n,x) returns the $n$th Fibonaccip polynomial in the variable x. If n is a positive or negative integer, it will be evaluated following the definition: $F_0(x) = 0 ; F_1(x) = 1 ; F_n(x) = x F_{n-1}(x) + F_{n-2}(x) $ \section{Stirling Numbers} \index{Stirling Numbers}\ttindex{Stirling1}\ttindex{Stirling2} Stirling numbers of the first and second kind are computed by the binary operators {\tt Stirling1} and {\tt Stirling2} using explicit formulae. \section{The \texorpdfstring{$\Gamma$}{Gamma} Function, and Related Functions} \ttindex{Gamma}\index{$\Gamma$ function}\index{Gamma function} \subsection{The \texorpdfstring{$\Gamma$}{Gamma} Function} This is represented by the unary operator {\tt Gamma}. Initial transformations applied with {\tt ROUNDED} off are: $\Gamma(n)$ for integral $n$ is computed, $\Gamma(n+1/2)$ for integral $n$ is rewritten to an expression in $\sqrt\pi$, $\Gamma(n+1/m)$ for natural $n$ and $m$ a positive integral power of 2 less than or equal to 64 is rewritten to an expression in $\Gamma(1/m)$, expressions with arguments at which there is a pole are replaced by {\tt INFINITY}, and those with a negative (real) argument are rewritten so as to have positive arguments. The algorithm used for numerical approximation is an implementation of an asymptotic series for $\ln(\Gamma)$, with a scaling factor obtained from the Pochhammer functions. An expression for $\Gamma'(z)$ in terms of $\Gamma$ and $\psi$ is included. \subsection{The Pochhammer Notation} \ttindex{Pochhammer}\index{Pochhammer notation} The Pochhammer notation $(a)_k$ is supported by the binary operator {\tt Pochhammer}. With {\tt ROUNDED} off, this expression is evaluated numerically if $a$ and $k$ are both integral, and otherwise may be simplified where appropriate. The simplification rules are based upon algorithms supplied by Wolfram Koepf \cite{Koepf:92}. \subsection{The Digamma Function, $\psi$} \ttindex{PSI}\index{$\psi$ function}\index{psi function}\index{Digamma function} This is represented by the unary operator {\tt PSI}. Initial transformations for $\psi$ are applied on a similar basis to those for $\Gamma$; where possible, $\psi(x)$ is rewritten in terms of $\psi(1)$ and $\psi(\frac{1}{2})$, and expressions with negative arguments are rewritten to have positive ones. Numerical evaluation of $\psi$ is only carried out if the argument is real. The algorithm used is based upon an asymptotic series, with a suitable scaler. Relations for the derivative and integral of $\psi$ are included. \subsection{The Polygamma Functions, $\psi^{(n)}$} \ttindex{Polygamma}\index{$\psi^{(n)}$ functions}\index{Polygamma functions} The $n$th derivative of the $\psi$ function is represented by the binary operator {\tt Polygamma}, whose first argument is $n$. Initial manipulations on $\psi^{(n)}$ are few; where the second argument is $1$ or $3/2$, the expression is rewritten to one involving the Riemann $\zeta$ function, and when the first is zero it is rewritten to $\psi$; poles are also handled. Numerical evaluation is only carried out with real arguments. The algorithm used is again an asymptotic series with a scaling factor; for negative (second) arguments, a Reflection Formula is used, introducing a term in the $n$th derivative of $\cot(z\pi)$. Simple relations for derivatives and integrals are provided. \subsection{The Riemann $\zeta$ Function} \ttindex{Zeta}\index{Riemann Zeta function}\index{Zeta function}\index{$\zeta$ function} This is represented by the unary operator {\tt Zeta}. With {\tt ROUNDED} off, $\zeta(z)$ is evaluated numerically for even integral arguments in the range $-31 < z < 31$, and for odd integral arguments in the range $-30 < z < 16$. Outside this range the values become a little unwieldy. Numerical evaluation of $\zeta$ is only carried out if the argument is real. The algorithms used for $\zeta$ are: for odd integral arguments, an expression relating $\zeta(n)$ with $\psi^{n-1}(3)$; for even arguments, a trivial relationship with the Bernoulli numbers; and for other arguments the approach is either (for larger arguments) to take the first few primes in the standard over-all-primes expansion, and then continue with the defining series with natural numbers not divisible by these primes, or (for smaller arguments) to use a fast-converging series obtained from \cite{Bender:78}. There are no rules for differentiation or integration of $\zeta$. \section{Bessel Functions} \ttindex{BesselJ}\ttindex{BesselY}\ttindex{BesselI}\ttindex{BesselK}\ttindex{Hankel1}\ttindex{Hankel2}\index{Bessel functions}\index{Hankel functions} Support is provided for the Bessel functions J and Y, the modified Bessel functions I and K, and the Hankel functions of the first and second kinds. The relevant operators are, respectively, {\tt BesselJ}, {\tt BesselY}, {\tt BesselI}, {\tt BesselK}, {\tt Hankel1} and {\tt Hankel2}, which are all binary operators. The following initial transformations are performed: \begin{itemize} \item trivial cases or poles of J, Y, I and K are handled; \item J, Y, I and K with negative first argument are transformed to have positive first argument; \item J with negative second argument is transformed for positive second argument; \item Y or K with non-integral or complex second argument is transformed into an expression in J or I respectively; \item derivatives of J, Y and I are carried out; \item derivatives of K with zero first argument are carried out; \item derivatives of Hankel functions are carried out. \end{itemize} Also, if the {\tt COMPLEX} switch is on and {\tt ROUNDED} is off, expressions in Hankel functions are rewritten in terms of Bessels. No numerical approximation is provided for the Bessel K function, or for the Hankel functions for anything other than special cases. The algorithms used for the other Bessels are generally implementations of standard ascending series for J, Y and I, together with asymptotic series for J and Y; usually, the asymptotic series are tried first, and if the argument is too small for them to attain the current precision, the standard series are applied. An obvious optimization prevents an attempt with the asymptotic series if it is clear from the outset that it will fail. There are no rules for the integration of Bessel and Hankel functions. \section{Hypergeometric and Other Functions} \ttindex{Beta}\ttindex{KummerM}\ttindex{KummerU}\ttindex{StruveH} \ttindex{StruveL}\ttindex{Lommel1}\ttindex{Lommel2}\ttindex{WhittakerM} \ttindex{WhittakerW}\index{Beta function}\index{$B$ function} \index{Kummer functions}\index{Struve functions}\index{Lommel functions} \index{Whittaker functions}\index{Hypergeometric functions} This package also provides some support for other functions, in the form of algebraic simplifications: \begin{itemize} \item The Beta function, a variation upon the $\Gamma$ function\cite{Abramowitz:72}, with the binary operator {\tt Beta}; \item The Struve {\bf H} and {\bf L} functions, through the binary operators {\tt StruveH} and {\tt StruveL}, for which manipulations are provided to handle special cases, simplify to more readily handled functions where appropriate, and differentiate with respect to the second argument; \item The Lommel functions of the first and second kinds, through the ternary operators {\tt Lommel1} and {\tt Lommel2}, for which manipulations are provided to handle special cases and simplify where appropriate; \item The Kummer confluent hypergeometric functions M and U (the hypergeometric ${_1F_1}$ or $\Phi$, and $z^{-a}{_2F_0}$ or $\Psi$, respectively), with the ternary operators {\tt KummerM} and {\tt KummerU}, for which there are manipulations for special cases and simplifications, derivatives and, for the M function, numerical approximations for real arguments; \item The Whittaker M and W functions, variations upon the Kummer functions, which, with the ternary operators {\tt WhittakerM} and {\tt WhittakerW}, simplify to expressions in the Kummer functions. \end{itemize} \section{Integral Functions} The SPECFN package includes manipulation and a limited numerical evaluation for some Integral functions, namely erf, erfc, Si, Shi, si, Ci, Chi, Ei, li, Fresnel\_C and Fresnel\_S. The definitions from integral, the derviatives and some limits are known together with some simple properties such as symmetry conditions. The numerical approximation for the Integral functions suffer from the fact that the precision is not set correctly for values of the argument above 10.0 (approx.) and from the usage of summations even for large arguments. $li$ is simplified towards $Ei(ln(z))$ . \section{Airy Functions} \ttindex{Airy\_Ai}\ttindex{Airy\_Bi}\ttindex{Airy\_Aiprime} \ttindex{Airy\_Biprime}\index{Airy Functions} Support is provided for the Airy Functions Ai and Bi and for the Airyprime Functions Aiprime and Biprime. The relevant operators are respectively {\tt Airy\_Ai}, {\tt Airy\_Bi}, {\tt Airy\_Aiprime}, and {\tt Airy\_Biprime}, which are all unary operators with one argument. The following cases can be performed: \begin{itemize} \item Trivial cases of Airy\_Ai and Airy\_Bi and their primes are handled. \item All cases can handle both complex and real arguments. \item The Airy Functions can also be represented in terms of Bessel Functions by activating an inactive rule set. \end{itemize} In order to activate the Airy Function to Bessel Rules one should type: \\ {\tt let Airy2Bessel\_rules;}. As a result the Airy\_Ai function, for example will be calculated using the formula :- \\ \\ {\tt Ai(z) = } $\frac{1}{3}$\( \sqrt{z} \)[{\bf {\sl I}}$_{-1/3}$($\zeta$) - {\bf {\sl I}}$_{1/3}$({$\zeta$})] , where $\zeta$ = $\frac{2}{3} z^{\frac{2}{3}}$\\ \\ \underline{{\tt Note}}:- In order to obtain satisfactory approximations to results both the {\tt COMPLEX} and {\tt ROUNDED} switches must be on. The algorithms used for the Airy Functions are implementations of standard ascending series, together with asymptotic series. At some point it is better to use the asymptotic approach, rather than the series. This value is calculated by the program and depends on the given precision. There are no rules for the integration of Airy Functions. \section{Polynomial Functions} Two groups are defined, some well-known orthogonal Polynomials (Hermite, Jacobi, Legendre, Laguerre, Chebyshev, Gegenbauer) and Euler and Bernoulli Polynomials. The names of the \REDUCE\ operator are build by adding a P to the name of the polynomials, e.g. EulerP implements the Euler polynomials. Most definitions are equivalent to \cite{Abramowitz:72}, except for the ternary (associated) Legendre Polynomials. \begin{verbatim} P(n,m,x) = (-1)^m *(1-x^2)^(m/2)*df(legendreP (n,x),x,m) \end{verbatim} \section{Spherical and Solid Harmonics} \ttindex{SolidHarmonicY} \ttindex{SphericalHarmonicY} The relevant operators are, respectively,\\ {\tt SolidHarmonicY} and {\tt SphericalHarmonicY}. The SolidHarmonicY operator implements the Solid Harmonics described below. It expects 6 parameter, namely n,m,x,y,z and r2 and returns a polynomial in x,y,z and r2. The operator SphericalHarmonicY is a special case of SolidHarmonicY with the usual definition: \begin{verbatim} algebraic procedure SphericalHarmonicY(n,m,theta,phi); SolidHarmonicY(n,m,sin(theta)*cos(phi), sin(theta)*sin(phi),cos(theta),1)$ \end{verbatim} Solid Harmonics of order n (Laplace polynomials) are homogeneous polynomials of degree n in x,y,z which are solutions of Laplace equation:- \begin{verbatim} df(P,x,2) + df(P,y,2) + df(P,z,2) = 0. \end{verbatim} There are 2*n+1 independent such polynomials for any given $n >=0$ and with:- \begin{verbatim} w!0 = z, w!+ = i*(x-i*y)/2, w!- = i*(x+i*y)/2, \end{verbatim} they are given by the Fourier integral:- \begin{verbatim} S(n,m,w!-,w!0,w!+) = (1/(2*pi)) * for u:=-pi:pi integrate (w!0 + w!+ * exp(i*u) + w!- * exp(-i*u))^n * exp(i*m*u) * du; \end{verbatim} which is obviously zero if $|m| > n$ since then all terms in the expanded integrand contain the factor exp(i*k*u) with k neq 0, S(n,m,x,y,z) is proportional to \begin{verbatim} r^n * Legendre(n,m,cos theta) * exp(i*phi) \end{verbatim} Let r2 = $x^2 + y^2 + z^2$ and r = sqrt(r2). The spherical harmonics are simply the restriction of the solid harmonics to the surface of the unit sphere and the set of all spherical harmonics {$n >=0; -n <= m =< n$} form a complete orthogonal basis on it, i.e. $<n,m|n',m'>$ = Kronecker\_delta(n,n') * Kronecker\_delta(m,m') using $<...|...>$ to designate the scalar product of functions over the spherical surface. The coefficients of the solid harmonics are normalised in what follows to yield an ortho-normal system of spherical harmonics. Given their polynomial nature, there are many recursions formulae for the solid harmonics and any recursion valid for Legendre functions can be 'translated' into solid harmonics. However the direct proof is usually far simpler using Laplace's definition. It is also clear that all differentiations of solid harmonics are trivial, qua polynomials. Some substantial reduction in the symbolic form would occur if one maintained throughout the recursions the symbol r2 (r cannot occur as it is not rational in x,y,z). Formally the solid harmonics appear in this guise as more compact polynomials in (x,y,z,r2). Only two recursions are needed:- (i) along the diagonal (n,n); (ii) along a line of constant n: (m,m),(m+1,m),...,(n,m). Numerically these recursions are stable. For $m < 0$ one has:- \begin{verbatim} S(n,m,x,y,z) = (-1)^m * S(n,-m,x,-y,z); \end{verbatim} \section{Jacobi's Elliptic Functions} The following functions have been implemented: \begin{itemize} \item The Twelve Jacobi Functions \item Arithmetic Geometric Mean \item Descending Landen Transformation \end{itemize} \subsection{Jacobi Functions} The following Jacobi functions are available:- \begin{itemize} \item Jacobisn(u,m) \item Jacobidn(u,m) \item Jacobicn(u,m) \item Jacobicd(u,m) \item Jacobisd(u,m) \item Jacobind(u,m) \item Jacobidc(u,m) \item Jacobinc(u,m) \item Jacobisc(u,m) \item Jacobins(u,m) \item Jacobids(u,m) \item Jacobics(u,m) \end{itemize} They will be evaluated numerically if the {\tt rounded} switch is used. \subsection{Amplitude} The amplitude of u can be evaluated using the {\tt JacobiAmplitude(u,m)} command. \subsection{Arithmetic Geometric Mean} A procedure to evaluate the AGM of initial values \(a_0,b_0,c_0\) exists as \\ {\tt AGM\_function(\(a_0,b_0,c_0\))} and will return \\ $\{ N, AGM, \{ a_N, \ldots ,a_0\}, \{ b_N, \ldots ,b_0\}, \{c_N, \ldots ,c_0\}\}$, where N is the number of steps to compute the AGM to the desired acuracy. \\ To determine the Elliptic Integrals K($m$), E($m$) we use initial values \(a_0 = 1\); \(b_0 = \sqrt{1-m}\) ; \(c_0 = \sqrt{m}\). \subsection{Descending Landen Transformation} The procedure to evaluate the Descending Landen Transformation of phi and alpha uses the following equations:\\ \indent \ \ \ \ \( (1+sin \alpha_{n+1})(1+cos \alpha_n)=2 \) \ \ \ \ where \(\alpha_{n+1}<\alpha_n\) \\ \indent \ \ \ \ \(tan(\phi_{n+1}-\phi_n)=cos \alpha_n tan \phi_n \) \ \ \ where \(\phi_{n+1}>\phi_n\) \\ It can be called using {\tt landentrans($\phi_0$,$\alpha_0$)} and will return \\ $\{\{\phi_0, \ldots ,\phi_n\},\{\alpha_0, \ldots ,\alpha_n\}\}$. \section{Elliptic Integrals} The following functions have been implemented: \begin{itemize} \item Elliptic Integrals of the First Kind \item Elliptic Integrals of the Second Kind %\item Ellpitic Integrals of the Third Kind \item Jacobi $\theta$ Functions \item Jacobi $\zeta$ Function \end{itemize} \subsection{Elliptic F} The Elliptic F function can be used as {\tt EllipticF($\phi$,m)} and will return the value of the {\underline {Elliptic Integral of the First Kind}}. \subsection{Elliptic K} The Elliptic K function can be used as {\tt EllipticK(m)} and will return the value of the {\underline {Complete Elliptic Integral of the First Kind}}, K. It is often used in the calculation of other elliptic functions \subsection{Elliptic K$'$} The Elliptic K$'$ function can be used as {\tt EllipticK!$'$(m)} and will return the value K($1-m$). \subsection{Elliptic E} The Elliptic E function comes with two different numbers of arguments: It can be used with two arguments as {\tt EllipticE($\phi$,m)} and will return the value of the {\underline {Elliptic Integral of the Second Kind}}. The Elliptic E function can also be used as {\tt EllipticE(m)} and will return the value of the {\underline {Complete Elliptic Integral of the Second Kind}}, E. %\section{Ellpitic $\Pi$} % %The Elliptic $\pi$ function can be used as {\tt EllipticPi( )} and %will return the value of the {\underline {Elliptic Integral of the %Third Kind}}. % \subsection{Elliptic $\Theta$ Functions} This can be used as {\tt EllipticTheta(a,u,m)}, where $a$ is the index for the theta functions ($a = 1,2,3$ or $4$) and will return $H$; $H_1$; $\Theta_1$; $\Theta$. (Also denoted in some texts as $\vartheta_1$; $\vartheta_2$; $\vartheta_3$; $\vartheta_4$.) \subsection{Jacobi's Zeta Function Z } This can be used as {\tt JacobiZeta(u,m)} and will return Jacobi Zeta. Note: the operator {\tt Zeta} will invoke Riemann's $\zeta$ function. \section{Lambert's W function} Lambert's W function is the inverse of the function $w*e^w$. Therefore it is an important contribution for the solve package. The function is studied extensively in \cite{Corless:92}. The current implementation will compute the principal branch in ROUNDED mode only. \section{3j symbols and Clebsch-Gordan Coefficients} The operators {\tt ThreeJSymbol}, {\tt Clebsch\_Gordan} are defined like in \cite{Landolt:68} or \cite{Edmonds:57}. ThreeJSymbol expects as arguments three lists of values \{$j_i,m_i$\}, e.g. \begin{verbatim} ThreeJSymbol({J+1,M},{J,-M},{1,0}); Clebsch_Gordan({2,0},{2,0},{2,0}); \end{verbatim} \section{6j symbols } The operator {\tt SixJSymbol} is defined like in \cite{Landolt:68} or \cite{Edmonds:57}. SixJSymbol expects two lists of values \{$j_1,j_2,j_3$\} and \{$l_1,l_2,l_3$\} as arguments, e.g. \begin{verbatim} SixJSymbol({7,6,3},{2,4,6}); \end{verbatim} In the current implementation of the SixJSymbol, there is only a limited reasoning about the minima and maxima of the summation using the INEQ package, such that in most cases the special 6j-symbols (see e.g. \cite{Landolt:68}) will not be found. \section{Acknowledgements} The contributions of Kerry Gaskell, Matthew Rebbeck, Lisa Temme, Stephen Scowcroft and David Hobbs (all students from the University of Bath on placement in ZIB Berlin for one year) were very helpful to augment the package. The advice of Ren\'e Grognard (CSIRO , Australia) for the development of the module for Clebsch-Gordan and 3j, 6j symbols and the module for spherical and solid harmonics was very much appreciated. \section{Table of Operators and Constants} \fbox{ \begin{tabular}{r l}\\ Function & Operator \\\\ %\hline $J_\nu(z)$ & {\tt BesselJ(nu,z)}\\ $Y_\nu(z)$ & {\tt BesselY(nu,z)}\\ $I_\nu(z)$ & {\tt BesselI(nu,z)}\\ $K_\nu(z)$ & {\tt BesselK(nu,z)}\\ $H^{(1)}_\nu(z)$ & {\tt Hankel1(n,z)}\\ $H^{(2)}_\nu(z)$ & {\tt Hankel2(n,z)}\\ ${\bf H}_{\nu}(z)$ & {\tt StruveH(nu,z)}\\ ${\bf L}_{\nu}(z)$ & {\tt StruveL(n,z)}\\ $s_{a,b}(z)$ & {\tt Lommel1(a,b,z)}\\ $S_{a,b}(z)$ & {\tt Lommel2(a,b,z)}\\ $Ai(z)$ & {\tt Airy\_Ai(z)}\\ $Bi(z)$ & {\tt Airy\_Bi(z)}\\ $Ai'(z)$ & {\tt Airy\_Aiprime(z)}\\ $Bi'(z)$ & {\tt Airy\_Biprime(z)}\\ $M(a, b, z)$ or $_1F_1(a, b; z)$ or $\Phi(a, b; z)$ & {\tt KummerM(a,b,z)} \\ $U(a, b, z)$ or $z^{-a}{_2F_0(a, b; z)}$ or $\Psi(a, b; z)$ & {\tt KummerU(a,b,z)}\\ $M_{\kappa,\mu}(z)$ & {\tt WhittakerM(kappa,mu,z)}\\ $W_{\kappa,\mu}(z)$ & {\tt WhittakerW(kappa,mu,z)}\\ \\ Fibonacci Numbers $F_{n}$ & {\tt Fibonacci(n)}\\ Fibonacci Polynomials $F_{n}(x)$ & {\tt FibonacciP(n)}\\ $B_n(x)$ & {\tt BernoulliP(n,x)}\\ $E_n(x)$ & {\tt EulerP(n,x)}\\ $C_n^{(\alpha)}(x)$ & {\tt GegenbauerP(n,alpha,x)}\\ $H_n(x)$ & {\tt HermiteP(n,x)}\\ $L_n(x)$ & {\tt LaguerreP(n,x)}\\ $L_n^{(m)}(x)$ & {\tt LaguerreP(n,m,x)}\\ $P_n(x)$ & {\tt LegendreP(n,x)}\\ $P_n^{(m)}(x)$ & {\tt LegendreP(n,m,x)}\\ \end{tabular}} \fbox{ \begin{tabular}{r l}\\ Function & Operator \\\\ %\hline $P_n^{(\alpha,\beta)} (x)$ & {\tt JacobiP(n,alpha,beta,x)}\\ $U_n(x)$ & {\tt ChebyshevU(n,x)}\\ $T_n(x)$ & {\tt ChebyshevT(n,x)}\\ $Y_n^{m}(x,y,z,r2)$ & {\tt SolidHarmonicY(n,m,x,y,z,r2)}\\ $Y_n^{m}(\theta,\phi)$ & {\tt SphericalHarmonicY(n,m,theta,phi)}\\ $\left( {j_1 \atop m_1} {j_2 \atop m_2} {j_3 \atop m_3} \right)$ & {\tt ThreeJSymbol(\{j1,m1\},\{j2,m2\},\{j3,m3\})}\\ $\left( {j_1m_1j_2m_2 | j_1j_2j_3 - m_3} \right)$ & {\tt Clebsch\_Gordan(\{j1,m1\},\{j2,m2\},\{j3,m3\})}\\ $\left\{ {j_1 \atop l_1} {j_2 \atop l_2} {j_3 \atop l_3} \right\}$ & {\tt SixJSymbol(\{j1,j2,j3\},\{l1,l2,l3\})}\\ \\ $sn(u|m)$ & {\tt Jacobisn(u,m)}\\ $dn(u|m)$ & {\tt Jacobidn(u,m)}\\ $cn(u|m)$ & {\tt Jacobicn(u,m)}\\ $cd(u|m)$ & {\tt Jacobicd(u,m)}\\ $sd(u|m)$ & {\tt Jacobisd(u,m)}\\ $nd(u|m)$ & {\tt Jacobind(u,m)}\\ $dc(u|m)$ & {\tt Jacobidc(u,m)}\\ $nc(u|m)$ & {\tt Jacobinc(u,m)}\\ $sc(u|m)$ & {\tt Jacobisc(u,m)}\\ $ns(u|m)$ & {\tt Jacobins(u,m)}\\ $ds(u|m)$ & {\tt Jacobids(u,m)}\\ $cs(u|m)$ & {\tt Jacobics(u,m)}\\ $F(\phi|m)$ & {\tt EllipticF(phi,m)}\\ $K(m)$ & {\tt EllipticK(m)}\\ $E(\phi|m) or E(m)$ & {\tt EllipticE(phi,m) or EllipticE(m)}\\ $H(u|m), H_1(u|m), \Theta_1(u|m), \Theta(u|m)$ & {\tt EllipticTheta(a,u,m)}\\ $\theta_1(u|m), \theta_2(u|m), \theta_3(u|m), \theta_4(u|m)$ & {\tt EllipticTheta(a,u,m)}\\ $Z(u|m)$ & {\tt Zeta\_function(u,m)}\\ \\ Lambert $\omega(z)$ & {\tt Lambert\_W(z)} \\ \\ Constant & REDUCE name \\\\ Euler's $\gamma$ constant & {\tt Euler\_gamma}\\ Catalan's constant & {\tt Catalan}\\ Khinchin's constant & {\tt Khinchin}\\ Golden ratio & {\tt Golden\_ratio}\\ \end{tabular}} \newpage \fbox{ \begin{tabular}{r l}\\ \\ Function & Operator \\ \\ $\left( { n \atop m } \right)$ & {\tt Binomial(n,m)} \\ Motzkin(n) & {\tt Motzkin(n)}\\ Bernoulli($n$) or $ B_n $ & {\tt Bernoulli(n)} \\ Euler($n$) or $ E_n $ & {\tt Euler(n)} \\ $S_n^{(m)}$ & {\tt Stirling1(n,m)} \\ ${\bf S}_n^{(m)}$ & {\tt Stirling2(n,m)} \\ $B(z,w)$ & {\tt Beta(z,w)}\\ $\Gamma(z)$ & {\tt Gamma(z)} \\ normalized incomplete Beta $I_{x}(a,b)=\frac{\textstyle B_{x}(a,b)}{\textstyle B(a,b)}$ & {\tt iBeta(a,b,x)}\\ % http://dlmf.nist.gov/8.2.E4 normalized incomplete Gamma $P(a,z)=\frac{\textstyle\gamma(a,z)}{\textstyle\Gamma(a)}$ & {\tt iGamma(a,z)} \\ incomplete Gamma $\gamma(a,z)$ & {\tt m\_gamma(a,z)} \\ $(a)_k$ & {\tt Pochhammer(a,k)} \\ $\psi(z)$ & {\tt Psi(z)} \\ $\psi^{(n)}(z)$ & {\tt Polygamma(n,z)} \\ Riemann's $\zeta(z)$ & {\tt Zeta(z)} \\ \\ $Si(z)$ & {\tt Si(z) }\\ $si(z)$ & {\tt s\_i(z) }\\ $Ci(z)$ & {\tt Ci(z) }\\ $Shi(z)$ & {\tt Shi(z) }\\ $Chi(z)$ & {\tt Chi(z) }\\ $erf(z)$ & {\tt erf(z) }\\ $erfc(z)$ & {\tt erfc(z) }\\ $Ei(z)$ & {\tt Ei(z) }\\ $li(z)$ & {\tt li(z) }\\ $C(x)$ & {\tt Fresnel\_C(x)} \\ $S(x)$ & {\tt Fresnel\_S(x)} \\ \\ $dilog(z)$ & {\tt dilog(z)} \\ $Li_{n}(z)$ & {\tt Polylog(n,z)}\\ Lerch's transcendent $\Phi(z,s,a)$ & {\tt Lerch\_Phi(z,s,a)}\\ \end{tabular}} \bibliography{specfn} \bibliographystyle{plain} \end{document}
\documentclass[aps,notitlepage,nofootinbib,10pt]{revtex4-1} % linking references \usepackage{hyperref} \hypersetup{ breaklinks=true, colorlinks=true, linkcolor=blue, filecolor=magenta, urlcolor=cyan, } %%% standard header % \usepackage[margin=1in]{geometry} % one inch margins \usepackage{fancyhdr} % easier header and footer management \pagestyle{fancyplain} % page formatting style \setlength{\parindent}{0cm} % don't indent new paragraphs... \parskip 6pt % ... place a space between paragraphs instead \usepackage[inline]{enumitem} % include for \setlist{}, use below %\setlist{nolistsep} % more compact spacing between environments \setlist[itemize]{leftmargin=*} % nice margins for itemize ... \setlist[enumerate]{leftmargin=*} % ... and enumerate environments \frenchspacing % add a single space after a period \usepackage{lastpage} % for referencing last page \cfoot{\thepage~of \pageref{LastPage}} % "x of y" page labeling %%% symbols, notations, etc. \usepackage{physics,braket,bm,commath,amssymb} % physics and math \renewcommand{\t}{\text} % text in math mode \newcommand{\f}[2]{\dfrac{#1}{#2}} % shorthand for fractions \newcommand{\p}[1]{\left(#1\right)} % parenthesis \renewcommand{\sp}[1]{\left[#1\right]} % square parenthesis \renewcommand{\set}[1]{\left\{#1\right\}} % curly parenthesis \renewcommand{\v}{\bm} % bold vectors \newcommand{\uv}[1]{\hat{\v{#1}}} % unit vectors \renewcommand{\d}{\partial} % partial d \renewcommand{\c}{\cdot} % inner product \newcommand{\bk}{\Braket} % shorthand for braket notation \let\vepsilon\epsilon % remap normal epsilon to vepsilon \let\vphi\phi % remap normal phi to vphi %%% figures \usepackage{graphicx,grffile,float,subcaption} % floats, etc. \usepackage{multirow} % multirow entries in tables \usepackage{footnote} % footnotes in floats \usepackage[font=small,labelfont=bf]{caption} % caption text options \usepackage{dsfont} \newcommand{\1}{\mathds{1}} \newcommand{\up}{\uparrow} \newcommand{\dn}{\downarrow} \newcommand{\E}{\mathcal{E}} \renewcommand{\H}{\mathcal{H}} \newcommand{\K}{\mathcal{K}} \newcommand{\Z}{\mathbb{Z}} \usepackage{accents} \newcommand{\utilde}[1]{\underaccent{\tilde}{#1}} \newcommand{\g}{\text{g}} \newcommand{\e}{\text{e}} \renewcommand{\headrulewidth}{0.5pt} % horizontal line in header \lhead{Michael A. Perlin} \begin{document} % \titlespacing{\section}{0pt}{6pt}{0pt} % section title placement % \titlespacing{\subsection}{5mm}{6pt}{0pt} % subsection title placement \section{Particle in a lattice} In a periodic potential $V\p{x}=V\p{x+a}$, Bloch's theorem states that the energy eigenstates $\phi^{\p n}_q\p{x}$ take the form \begin{align} \phi^{\p n}_q\p{x} = e^{iqx} u^{\p n}_q\p{x}, \end{align} where $u^{\p n}_q\p{x}=u^{\p n}_q\p{x+a}$ has the same periodicity as $V$ and $\abs{q}\le\pi/a$. We can then find that \begin{multline} \d_x^2\phi^{\p n}_q = \d_x^2\p{e^{iqx} u^{\p n}_q} = \d_x\sp{iqe^{iqx} u^{\p n}_q + e^{iqx}\d_xu^{\p n}_q} \\ = -q^2e^{iqx}u^{\p n}_q + iqe^{iqx} \d_xu^{\p n}_q + iqe^{iqx} \d_xu^{\p n}_q + e^{iqx}\d_x^2u^{\p n}_q \\ = -\p{q^2 + 2qp + p^2}\phi^{\p n}_q = -\p{q+p}^2\phi^{\p n}_q, \end{multline} which implies that the Schroedinger equation is \begin{align} \p{-\f{\p{p+q}^2}{2m} + V - E_q^{\p n}}\phi^{\p n}_q = 0. \end{align} Alternately, letting $y=kx$ we can expand the Schroedinger equation as \begin{align} \p{-\f{k^2}{2m}\d_y^2 + V - E_q^{\p n}}\phi^{\p n}_q = 0. \end{align} Defining the recoil energy $E_R=k^2/\p{2m}$ and using the notation $\tilde X\equiv X/E_R$, the Schroedinger equation becomes \begin{align} \p{\d_y^2 - \tilde V + \tilde E_q^{\p n}}\phi^{\p n}_q = 0. \end{align} If $V=V_0\sin^2\p{kx}$, then \begin{align} \p{\d_y^2 - \f{\tilde V_0}{2}\sp{1-\cos\p{2kx}} + \tilde E_q^{\p n}}\phi^{\p n}_q = \p{\d_y^2 + \sp{\tilde E_q^{\p n} - \f{\tilde V_0}{2}} - 2\sp{-\f{\tilde V_0}{4}}\cos\p{2y}}\phi^{\p n}_q = 0, \end{align} which is the Mathieu equation. \subsection{Wannier orbitals and tight-binding approximation} We can define the Wannier orbitals \begin{align} w_i^{\p n}\p{x} = w_n\p{x-x_i} = \f1{\sqrt{L}}\sum_q e^{-iqx_i}\phi_q^{\p n}\p{x}, \end{align} which describe a localized orbital at site $x_i$ (of $L$) with electronic state indexed by $n$. General wavefunctions can then be expanded as \begin{align} \psi\p{x,t} = \sum_{n,i}z_i^{\p n}\p{t}w_n\p{x-x_i}. \end{align} As the Wannier orbitals are orthonormal, we can project out a single coefficient as \begin{align} \int dx~ \bar w_m\p{x-x_j}\psi\p{x,t} = z_j^{\p m}. \end{align} The energy eigenvalue equation for a Hamiltonian $H=H_0+V$ for the background periodic potential $H_0$ and perturbation $V$ is \begin{align} i\d_t\psi = \p{H_0+V}\psi, \end{align} where we can project onto the orbital $w_j^{\p m}$ to get \begin{align} i\d_t z_j^{\p m} = \sum_{n,i}\p{\int dx~\bar w_j^{\p m} \p{H_0 + V} w_i^{\p n}}z_i^{\p n}. \end{align} Defining \begin{align} J_{j,i}^{m,n} \equiv \int dx~\bar w_j^{\p m} H_0 w_i^{\p n} && V_{j,i}^{m,n} \equiv \int dx~\bar w_j^{\p m} V w_i^{\p n}, \end{align} we can express \begin{align} i\d_t z_j^{\p m} = \sum_{n,i}\p{J_{j,i}^{m,n} + V_{j,i}^{m,n}}z_i^{\p n}. \end{align} We can expand \begin{multline} J_{j,i}^{m,n} = \int dx~\f1L\sum_{p,q} \p{e^{ipx_j}\bar \phi_p^{\p m}}H_0\p{e^{-iqx_i}\phi_q^{\p n}} = \f1L\sum_{p,q}E_q^{\p n}e^{i\p{px_j-qx_i}} \int dx~ \bar \phi_p^{\p m}\phi_q^{\p n} \\ = \f{E_q^{\p n}}{L}\sum_{p,q}e^{i\p{px_j-qx_i}}\delta_{m,n} \equiv J_{j,i}^{\p n}\delta_{m,n}, \end{multline} which means \begin{align} i\d_t z_j^{\p m} = \sum_i\p{J_{j,i}^{\p m}z_i^{\p m} + \sum_nV_{j,i}^{m,n}}z_i^{\p n}. \end{align} If the interband transitions induced by $V$ are sufficiently slow, i.e. \begin{align} \sum_{n\ne m}V_{j,i}^{m,n}\ll J_{j,i}^{\p m}+V_{j,i}^{m,m}, \end{align} we can make a single-band approximation by fixing $m$ and neglecting all $n\ne m$ to yield \begin{align} i\d_t z_j = \sum_i \p{J_{j,i} + V_{j,i}}z_i. \end{align} Furthermore, if the lattice in $H_0$ is sufficiently deep to neglect tunneling induced by $J_{j,i}$ beyond nearest-neighbor and the perturbation $V_{j,i}$ is slowly varying enough to be considered constant at each lattice site and weak enough to neglect all $V$-induced tunneling, i.e. $V_{j,i}=V_j\delta_{j,i}$, then \begin{align} i\d_t z_j = J_{j,j-1}z_{j-1} + J_{j,j+1}z_{j+1} + V_jz_j + J_{j,j}z_j. \end{align} We can now define \begin{align} \varepsilon_0 = \int dx~ \bar w_j H_0 w_j = \int dx~ \bar w_0 H_0 w_0 \end{align} and observe that by parity symmetry $J_{j,j-1}=J_{j,j+1}\equiv J$ to arrive at the discrete Schoeringer equation (DSE) \begin{align} i\d_t z_i = J\p{z_{i-1} + z_{i+1}} + V_i z_i + \varepsilon_0 z_i. \end{align} \newpage \section{Spin-orbit coupling in a Harmonic oscillator} Consider a two-level atom with energy splitting $\omega_0$ in a laser cavity with frequency $\omega$. The Hamiltonian for this system is \begin{align} H = \omega_0S_z + \omega\p{a^\dag a+\f12} - \v d\c\v E, \end{align} where $S_z=\sigma_z/2=\p{\op e - \op g}/2$; \begin{align} \v E\p{x,t} = \sqrt{\f{\omega\bk N}{2V}} \sp{u\p{x}a^\dag+u^*\p{x}a} \uv E \end{align} with photon occupation $a^\dag a=\bk N$, cavity volume $V$, and field mode $u\p{x}$ (e.g. $e^{ikx}$); and \begin{align} \v d = d_0\sigma_x\uv d = \p{\sigma_++\sigma_-}d_0\uv d. \end{align} Moving into the frame of the atom, \begin{align} \sigma_+ \to e^{i\omega_0t}\sigma_+, && \sigma_- \to e^{-i\omega_0t}\sigma_-, \end{align} which means \begin{align} \v d \to \p{e^{i\omega_0t}\sigma_++e^{-i\omega_0t}\sigma_-}d_0\uv d. \end{align} Similarly, in the frame of the field Hamiltonian \begin{align} a^\dag \to e^{i\omega t}a^\dag, && a \to e^{-i\omega t} a, \end{align} which means \begin{align} \v E \to \sqrt{\f{\omega\bk N}{2V}} \p{e^{i\omega t} u a^\dag + e^{-i\omega t} u^* a}u\uv E. \end{align} In the interaction picture of the atom and field, then, we have the Hamiltonian \begin{multline} H_I = -\tilde{\v d}\c\tilde{\v E} = -d_0\p{e^{i\omega_0t}\sigma_++e^{-i\omega_0t}\sigma_-} \sqrt{\f{\omega\bk N}{2V}} \p{e^{i\omega t} u a^\dag + e^{-i\omega t} u^* a}\uv d\c\uv E \\ \equiv \p{e^{i\omega_0t}\sigma_+ + e^{-i\omega_0t}\sigma_-} \p{\f{\Omega}{2}e^{i\omega t}a^\dag + \f{\Omega^*}{2}e^{-i\omega t}a} \end{multline} with \begin{align} \Omega\p{x} = -2d_0\sqrt{\f{\omega\bk N}{2V}}~u\p{x}\uv d\c\uv E. \end{align} If the detuning $\Delta=\omega-\omega_0$ is small (i.e. $\abs\Delta\ll\omega,\omega_0$) and $\abs\Omega\ll\omega+\omega_0$, then by the secular approximation \begin{align} H_I \approx \f{\Omega}{2}e^{i\Delta}\sigma_-a^\dag + \f{\Omega^*}{2}e^{-i\Delta}\sigma_+a \end{align} \newpage \section{Periodically-driven QHO} We start with the Hamiltonian for a a periodically driven QHO, \begin{align} H = \nu\p{a^\dag a + \f12} + F_0\cos\p{ft}x = \nu\p{a^\dag a + \f12} + F_0x_0\cos\p{ft}\p{a^\dag + a}. \end{align} In the interaction picture of the QHO, we have \begin{align} H_I = F_0x_0\cos\p{ft}\p{e^{i\nu t}a^\dag + e^{-i\nu t}a} = \f12F_0x_0\p{e^{ift}+e^{-ift}}\p{e^{i\nu t}a^\dag + e^{-i\nu t}a}. \end{align} Defining \begin{align} g = \f12 F_0x_0, && \xi = \nu - f, \end{align} we make the secular approximation ($\nu+f\gg g$) to neglect fast-oscillating terms, yielding \begin{align} H_I = g\p{e^{i\xi t}a^\dag + e^{-i\xi t}a}. \end{align} The time-evolution operator for infinitesimal time $\Delta t$ is then \begin{align} D = \exp\p{iH_I\Delta t} = \exp\sp{ig\p{e^{i\xi t}a^\dag + e^{-i\xi t}a}\Delta t} \equiv \exp\p{\alpha a^\dag - \alpha^*a} \equiv D\p\alpha, \end{align} where \begin{align} \alpha = ige^{i\xi t}\Delta t = \f{i}2F_0x_0e^{i\p{\nu-f}t}\Delta t. \end{align} Using the identity $e^Ae^B = e^{A+B}e^{\sp{A,B}/2}$ for operators $A$ an $B$ that commute with their commutator, we then get that \begin{multline} D\p\beta D\p\alpha = \exp\p{\p{\beta+\alpha} a^\dag - \p{\beta^*+\alpha^*}a} \exp\p{\f12\sp{\beta a^\dag - \beta^*a, \alpha a^\dag - \alpha^*a}} \\ = D\p{\beta+\alpha} \exp\p{-\f12\p{\beta\alpha^*+\beta^*\alpha}} = D\p{\beta+\alpha}\exp\p{i\Re\sp{\beta\alpha^*}}. \end{multline} The propagator is then \begin{align} U\p{t} = D\p{\alpha_N}\cdots D\p{\alpha_2}D\p{\alpha_1}, \end{align} where we take the limit as $N\to\infty$ and \begin{align} \alpha_n \equiv ge^{i\xi n\Delta t}\Delta t, && \Delta t = t/N. \end{align} We thus contract as infinitesimal displacement operators to find \begin{multline} U\p{t} = D\p{\alpha_N}\cdots D\p{\alpha_3}D\p{\alpha_1+\alpha_2} \exp\p{i\Re\sp{\alpha_2\alpha_1^*}} \\ = D\p{\alpha_N}\cdots D\p{\alpha_4}D\p{\alpha_1+\alpha_2+\alpha_3} \exp\p{i\Re\sp{\alpha_3\p{\alpha_1+\alpha_2}^*}} \exp\p{i\Re\sp{\alpha_2\alpha_1^*}} \\ = D\p{\sum_{n=1}^N\alpha_n} \prod_{n=1}^{N-1} \exp\p{i\Re\sp{\alpha_{n+1}\p{\sum_{m=1}^n\alpha_m}^*}}. \end{multline} Knowing that \begin{align} \sum_{k=1}^K x^k = x~\f{1-x^K}{1-x} = \f{1-x^K}{x^{-1}-1}, \end{align} we can compute \begin{align} \sum_{n=1}^N\alpha_n = g\Delta t\sum_{n=1}^N e^{i\xi n\Delta t} = g\Delta t~\f{1-e^{i\xi N\Delta t}}{e^{-i\xi\Delta t}-1} = \f{ig}{\xi}\p{1-e^{i\xi t}} \equiv \alpha\p{t}. \end{align} We will also need \begin{align} \alpha_{n+1}\p{\sum_{m=1}^n\alpha_m}^* = g^2\Delta t^2~e^{i\xi\p{n+1}\Delta t}\sum_{m=1}^ne^{-i\xi m\Delta t} = g^2\Delta t^2~e^{i\xi n\Delta t}~ \f{1-e^{-i\xi n\Delta t}}{1-e^{-i\xi\Delta t}} = \f{ig^2}{\xi}\Delta t\p{1-e^{-i\xi n\Delta t}}, \end{align} which we can use to find \begin{align} \sum_{n=1}^{N-1}\alpha_{n+1}\p{\sum_{m=1}^n\alpha_m}^* = \f{ig^2}{\xi}\Delta t\sum_{n=1}^{N-1}\p{1-e^{i\xi n\Delta t}} = \f{ig^2}{\xi}\int_0^t dt'~\p{1-e^{i\xi t'}} = g\int_0^t dt~\alpha\p{t} \end{align} Observing that \begin{align} d\alpha\p{t} = \f{ig}{\xi}\p{-i\xi dt} = g~dt, \end{align} we can say \begin{align} \sum_{n=1}^{N-1}\alpha_{n+1}\p{\sum_{m=1}^n\alpha_m}^* = \int_0^{\alpha\p{t}} d\alpha'~\alpha' = \f12\alpha\p{t}^2, \end{align} and so \begin{align} U\p{t} = D\sp{\alpha\p{t}} \exp\p{\f{i}{2}\Re\sp{\alpha\p{t}^2}}. \end{align} \newpage \section{Lattice Modulation} We begin with a ``background'' 1-D optical lattice clock Hamiltonian after diagonalization in quasi-momentum: \begin{align} H_B = \sum_{q,n,s}\p{E_{qns}-\f12s\delta} b_{qns}^\dag b_{qns} - \f12\sum_{q,n,s,m} \Omega_{nm}^{qs} b_{qm\bar s}^\dag b_{qns}. \label{eq:H_B} \end{align} If the lattice $V_0\sin^2\p{k_Lz}$ is modulated as $V_0\to V_0+\tilde V\cos\p{\nu t}$, then we pick up a modulation Hamiltonian $\tilde H = \tilde\H \cos\p{\nu t}$, where \begin{align} \tilde\H = \tilde V \sum_{\substack{q,n,s\\g,m}} \bk{gms|\sin^2\p{k_Lz}|qns} b_{gms}^\dag b_{qns} = \f12\tilde V\sp{1 - \sum_{\substack{q,n,s\\g,m}} \bk{gms|\cos\p{2k_Lz}|qns} b_{gms}^\dag b_{qns}}. \end{align} Recalling that, due to the gauge transformation performed to get to \eqref{eq:H_B}, \begin{align} \bk{zs|qns} = \bk{z|q+sk/2,n} = e^{i\p{q+sk/2}z} \sum_\kappa c_{q+sk/2,n}^{(\kappa)} e^{i2k_Lz\kappa}, \end{align} we can expand \begin{multline} \bk{gms|\cos\p{2k_Lz}|qns} = \f12 \int dz~ \p{e^{i2k_Lz}+e^{-i2k_Lz}} e^{i\p{q-g}z} \sum_{\kappa,\ell} e^{i2k_Lz\p{\kappa-\ell}} c_{g+sk/2,m}^{(\ell)} c_{q+sk/2,n}^{(\kappa)} \\ = \f12 \sum_{\kappa,\ell} \int dz~ e^{i\p{q-g}z} \p{e^{i2k_Lz\p{\kappa+1-\ell}} + e^{i2k_Lz\p{\kappa-1-\ell}}} c_{g+sk/2,m}^{(\ell)} c_{q+sk/2,n}^{(\kappa)}. \end{multline} This integral is vanishes unless $g=q$ and $\ell=\kappa\pm1$, so \begin{align} \bk{gms|\cos\p{2k_Lz}|qns} \approx \delta_{gq} \f12 \sum_\kappa \p{c_{q+sk/2,m}^{(\kappa+1)} c_{q+sk/2,n}^{(\kappa)} + c_{q+sk/2,m}^{(\kappa-1)} c_{q+sk/2,n}^{(\kappa)}}. \end{align} Letting \begin{align} V^{qs}_{nm} \equiv -\f12 \tilde V \bk{qms|\cos\p{2k_Lz}|qns} = -\f14 \tilde V \sum_\kappa \p{c_{q+sk/2,m}^{(\kappa+1)} c_{q+sk/2,n}^{(\kappa)} + c_{q+sk/2,m}^{(\kappa-1)} c_{q+sk/2,n}^{(\kappa)}}, \end{align} the modulated Hamiltonian is thus, up to a global shift in energy, \begin{align} \tilde\H = \sum_{q,n,s,m} V^{qs}_{nm} b_{qms}^\dag b_{qns}. \end{align} \subsection{Aside: Fourier expansions} We can expand, to first Fourier order, \begin{align} E_{qns} \approx E_n + \tilde E_n \cos\p{q + sk/2}, \end{align} \begin{align} \Omega^{qs}_{nm} \approx \Omega_{nms} + \tilde\Omega_{nms}^C\cos q + \tilde\Omega_{nm}^S\sin q, \end{align} \begin{align} V^{qs}_{nm} \approx V_{nm} + \tilde V_{nm} \f12\sp{e^{i\p{q+sk/2}}+\p{-1}^{n+m}e^{-i\p{q+sk/2}}}, \end{align} where $X_{nms}\in\set{\Omega_{nms},\tilde\Omega_{nms}^C}$ satisfies \begin{align} X_{nms} = \p{-1}^{n+m} X_{mns} = \p{-1}^{n+m} X_{nm\bar s} = X_{mn\bar s}, \end{align} and \begin{align} \tilde\Omega_{nm}^S = \tilde\Omega_{mn}^S, && V_{nm} = V_{mn}, && \tilde V_{nm} = \tilde V_{mn}. \end{align} Observing that $\tilde\Omega_{nn}^S=0$, we can say that \begin{align} \Omega^{qs}_{nn} \approx \Omega_n + \tilde\Omega_n\cos q. \end{align} Finally, we note that $V_{nm}=0$ when $n+m$ is odd, which means that \begin{align} V^{qs}_{nm} \approx \left\{ \begin{array}{ll} V_{nm} + \tilde V_{nm}\cos\p{q+sk/2} & n+m~\t{even} \\ \tilde V_{nm}\sin\p{q+sk/2} & n+m~\t{odd} \end{array}\right.. \end{align} \subsection{Interaction picture} The full Hamiltonian is now \begin{multline} H = \sum_{q,n,s}\p{E_{qns}-\f12s\delta} b_{qns}^\dag b_{qns} + \sum_{q,n,s,m} V^{qs}_{nm} \cos\p{\nu t} b_{qms}^\dag b_{qns} - \f12\sum_{q,n,s,m} \Omega_{nm}^{qs} b_{qm\bar s}^\dag b_{qns} \\ = \sum_{q,n,s} \p{E_{qns}-\f12s\delta+V^{qs}_{nn}\cos\p{\nu t}} b_{qns}^\dag b_{qns} + \sum_{\substack{q,n,s\\m\ne n}} V^{qs}_{nm} \cos\p{\nu t} b_{qms}^\dag b_{qns} - \f12\sum_{q,n,s,m} \Omega_{nm}^{qs} b_{qm\bar s}^\dag b_{qns}, \end{multline} and can be written in the interaction picture of the single-particle state energies as \begin{multline} H_I = \sum_{\substack{q,n,s\\m\ne n}} V^{qs}_{nm} \cos\p{\nu t} \exp\sp{i\p{E_{qms}-E_{qns}}t + i\p{V^{qs}_{mm}-V^{qs}_{nn}}\sin\p{\nu t}/\nu} b_{qms}^\dag b_{qns} \\ -\f12\sum_{q,n,s,m} \Omega_{nm}^{qs} \exp\sp{i\p{E_{qm\bar s}-E_{qns}+s\delta}t + i\p{V^{q\bar s}_{mm}-V^{qs}_{nn}}\sin\p{\nu t}/\nu} b_{qm\bar s}^\dag b_{qns}. \end{multline} We can expand \begin{align} \exp\p{i\beta\sin\tau} = \sum_\kappa \exp\p{i\kappa\tau} \f1{2\pi}\int_{-\pi}^\pi dx~ \exp\p{-i\kappa x+i\beta\sin x} = \sum_\kappa J_\kappa\p{\beta} \exp\p{i\kappa\tau}, \end{align} where $J_n\p{x}$ is the $n$-th order Bessel function of the first kind. Defining \begin{align} W^{qs}_{nm} \equiv \p{V^{qs}_{mm} - V^{qs}_{nn}}/\nu, && \bar W^{qs}_{nm} \equiv \p{V^{q\bar s}_{mm} - V^{qs}_{nn}}/\nu, \end{align} the Hamiltonian is therefore \begin{multline} H_I = \f12 \sum_{\substack{q,n,s,\\m\ne n\\\kappa,r}} V^{qs}_{nm} J_\kappa\p{W^{qs}_{nm}} \exp\sp{i\p{E_{qms}-E_{qns}+\sp{\kappa+r}\nu}t} b_{qms}^\dag b_{qns} \\ -\f12\sum_{\substack{q,n,s\\m,\kappa}} \Omega_{nm}^{qs} J_\kappa\p{\bar W^{qs}_{nm}} \exp\sp{i\p{E_{qm\bar s}-E_{qns}+s\delta+\kappa\nu}t} b_{qm\bar s}^\dag b_{qns}, \end{multline} where $r=\pm1$. \subsection{Nontrivial topology: example} We now restrict ourselves to considering only the first two bands, set $\nu=\p{E_1-E_0}/2$, and $\delta=\sp{E_1-E_0}/4$. The spin-flipping $\Omega^{qs}_{nm}$ terms can then be neglected by the secular approximation, and we are left with \begin{align} H_I = \f12 \sum_{q,s,\kappa,r} \utilde V^{qs}_{0,1} J_\kappa\p{\utilde W^{qs}_{0,1}} \exp\sp{i\p{\sp{E_1-E_0}\sp{1+\kappa/2+r/2} + \sp{\tilde E_1-\tilde E_0}\cos q}t} c_{q,1,s}^\dag c_{q,0,s} + \t{h.c.}, \end{align} where for $X^{qs}_{nm}\in\set{V^{qs}_{nm},W^{qs}_{nm}}$ we define $\utilde X^{qs}_{nm}\equiv X^{q-sk/2,s}_{nm}$. The only nonvanishing terms (from the secular approximation) are those with $\kappa=r=-1$, so \begin{align} H_I = -\f12 \sum_{q,s} \utilde V^{qs}_{0,1} J_1\p{\utilde W^{qs}_{0,1}} \exp\sp{i\p{\tilde E_1-\tilde E_0}\cos q~ t} c_{q,1,s}^\dag c_{q,0,s} + \t{h.c.}. \end{align} With appropriate choice of interaction picture, this Hamiltonian is equivalently \begin{align} H_I^{\t{eff}} = \sum_{q,n,s}\tilde E_n\cos q~ c_{qns}^\dag c_{qns} - \f12\sum_{q,n,s} \utilde V^{qs}_{n\bar n} J_1\p{\abs{\utilde W^{qs}_{n\bar n}}} c_{q\bar ns}^\dag c_{qns}. \end{align} Here $\utilde V^{qs}_{n\bar n} J_1\p{\utilde W^{qs}_{n\bar n}} \sim \sin q$, which implies that the energy bands of this Hamiltonian have Chern number $\pm1$. If we instead set $\delta=0$, we would get the effective Hamiltonian $H_I^{\t{eff}} = \sum_{q,n,s} h_{qns}$, where \begin{align} h_{qns} = \tilde E_{qns} b_{qns}^\dag b_{qns} - \f12 V^{qs}_{n\bar n} J_1\p{\abs{W^{qs}_{n\bar n}}} b_{q\bar ns}^\dag b_{qns} - \f12 \Omega^{qs}_{nn} J_0\p{\bar W^{qs}_{nn}} b_{qn\bar s}^\dag b_{qns} + \f12 \Omega^{qs}_{nn} J_1\p{\abs{\bar W^{qs}_{n\bar n}}} b_{q\bar n\bar s}^\dag b_{qns} \end{align} and $\tilde E_{qns}\equiv \tilde E_n \cos\p{q+sk/2}$. \newpage \subsection{Wannier basis} In terms of the field operators $\tilde a_{xns}$ for atoms localized on lattice sites $x\in a\Z_L$ (with $L$ sites total and lattice constant $a$) in bands $n\in\mathbb N_0$ with clock states $s\in\set{\pm 1}$, we can expand \begin{align} b_{qns}^\dag = c_{q+sk/2,ns}^\dag = \f1{\sqrt L}\sum_x e^{i\p{q+sk/2}x} \tilde a_{xns}^\dag = \f1{\sqrt L}\sum_x e^{iqx} a_{xns}^\dag, \end{align} where $a_{xns}^\dag\equiv e^{iskx/2}\tilde a_{xns}^\dag$. We can also expand, to first Fourier order in $q$, \begin{align} E_{qns} \approx E_n + \tilde E_n \cos\p{q+sk/2}, \end{align} \begin{align} \Omega^{qs}_{nm} \approx \Omega^s_{nm} + \tilde\Omega^s_{nm} \cos\p{q+\alpha^s_{nm}} && V^{qs}_{nm} \approx V_{nm} + \tilde V_{nm} \cos\p{q+sk/2+\beta_{nm}} \end{align} where we work in momentum units of $k_L/\pi$, such that $q\in\sp{-\pi,\pi}$ in the first Brillouin zone. The background Hamiltonian is then \begin{multline} H_B = \sum_{x,n,s}\p{E_n - \f12s\delta} a_{xns}^\dag a_{xns} - \f12 \sum_{x,n,s,m} \Omega^s_{nm} a_{xm\bar s}^\dag a_{xns} \\ + \f1{2L} \sum_{\substack{q,n,s\\x,y}} \tilde E_n \p{e^{isk/2}e^{iq} + e^{-isk/2}e^{-iq}} e^{iq\p{y-x}} a_{yns}^\dag a_{xns} \\ - \f1{4L} \sum_{\substack{q,n,s\\m,x,y}} \tilde\Omega^s_{nm} \p{e^{i\alpha^s_{nm}}e^{iq} + e^{-i\alpha^s_{nm}}e^{-iq}} e^{iq\p{y-x}} a_{ym\bar s}^\dag a_{xns}, \end{multline} which simplifies to \begin{multline} H_B = \sum_{x,n,s}\p{E_n - \f12s\delta} a_{xns}^\dag a_{xns} - \f12 \sum_{x,n,s,m} \Omega^s_{nm} a_{xns}^\dag a_{xm\bar s} \\ + \f12 \sum_{x,n,s} \tilde E_n \p{e^{-isk/2} a_{x+1,ns}^\dag a_{xns} + \t{h.c.}} - \f14 \sum_{x,n,s,m} \tilde\Omega^s_{nm} \p{e^{-i\alpha^s_{nm}} a_{x+1,m\bar s}^\dag a_{xns} + \t{h.c.}}. \end{multline} The modulated Hamiltonian is similarly \begin{align} \tilde\H = \sum_{x,n,s,m} V_{nm} a_{xms}^\dag a_{xns} + \f12\sum_{\substack{q,n,s\\m,x,y}} \tilde V_{nm} \p{e^{i\p{sk/2+\beta_{nm}}}e^{iq} + e^{-i\p{sk/2+\beta_{nm}}}e^{-iq}} e^{iq\p{y-x}} a_{yms}^\dag a_{xns}, \end{align} which simplifies to \begin{align} \tilde\H = \sum_{x,n,s,m}\sp{V_{nm} a_{xns}^\dag a_{xms} + \f12 \tilde V_{nm} \p{e^{-i\p{sk/2+\beta_{nm}}} a_{x+1,ms}^\dag a_{xns} + \t{h.c.}}}. \end{align} \newpage \section{Clock laser modulation} Our full 1-D OLC Hamiltonian after diagonalization in quasimomentum is \begin{align} H = \sum_{q,n,s}\sp{E_{qns} - \f12 s\delta\p{t}} b_{qns}^\dag b_{qns} - \f12 \sum_{q,n,s,m} \Omega^{qs}_{nm} b_{qm\bar s}^\dag b_{qns}. \end{align} If we expand, for $N$ drive frequencies \begin{align} \delta\p{t} = -\sum_{j=1}^N \delta_j \cos\p{\nu_j t + \phi_j} = -\sum_j \beta_j \nu_j \cos\p{\nu_j t + \phi_j}, && \beta_j \equiv \delta_j/\nu_j, \end{align} then we can write the Hamiltonian in the interaction picture of its diagonal elements to get \begin{align} H_I &= -\f12 \sum \Omega^{qs}_{nm} \exp\sp{i\p{E_{qm\bar s} - E_{qns}} t - is\sum_j\beta_j\sin\p{\nu_j t+\phi_j} + is\sum_j\beta_j\sin\phi_j} b_{qm\bar s}^\dag b_{qns}. \end{align} Using the Jacobi-Anger identity, we can expand \begin{align} \exp\sp{-is\sum_j\beta_j\sin\tau_j} = \prod_j \exp\p{-is\beta_j\sin\tau_j} = \prod_j \sum_{k_j} J\p{k_j,s\beta_j} \exp\p{-ik_j\tau_j} = \sum_{\v k} \prod_j J\p{k_j,s\beta_j} \exp\p{-ik_j\tau_j}, \end{align} where $J\p{n,x}$ is the first Bessel function of the first kind of order $n$ evaluated at $x$. We then have that \begin{align} H_I &= -\f12\sum_{q,n,s,m,\v k} \Omega^{qs}_{nm} \sp{\prod_j J\p{k_j,s\beta_j}} \exp\sp{i\p{E_{qm\bar s}-E_{qns}} t - i\sum_jk_j\p{\nu_jt+\phi_j} + is\sum_j\beta_j\sin\phi_j} b_{qm\bar s}^\dag b_{qns} \\ &= -\f12\sum_{q,n,s,m,\v k} f\p{\v k,\v\beta,\v\phi} \Omega^{qs}_{nm} \exp\sp{i\p{E_{qm\bar s}-E_{qns}-\v k\c\v\nu}t} b_{qm\bar s}^\dag b_{qns}, \end{align} where \begin{align} f\p{\v k,\v\beta,\v\phi} \equiv \sp{\prod_j J\p{k_j,s\beta_j}} \exp\p{-i\v k\c\v\phi + is\v\beta\c\sin\v\phi}. \end{align} If we now assume that \begin{enumerate*}[label=(\roman*)] \item all drive frequencies are much larger than the clock laser Rabi frequency $\Omega$, i.e. $\nu_j\gg\Omega$ for all $j$, and \item the difference between any two drive frequencies is much larger than the Rabi frequency $\Omega$, i.e. $\abs{\nu_j-\nu_k}\gg\Omega$ for all $j$ and $k$, \end{enumerate*} then we can define the vector $\v k^{qs}_{nm}\in\Z^N$ which minimizes $\abs{E_{qm\bar s}-E_{qns}-\v k^{qs}_{nm}\c\v\nu}$, and by the secular approximation say that \begin{align} H_I = -\f12\sum_{q,n,s,m} f\p{\v k^{qs}_{nm},\v\beta,\v\phi} \Omega^{qs}_{nm} \exp\sp{i\p{E_{qm\bar s}-E_{qns}-\v k^{qs}_{nm}\c\v\nu}t} b_{qm\bar s}^\dag b_{qns}. \end{align} Fixing some initial state $\ket\phi=\ket{q_0n_0s_0}$, we now define the vector $\v\ell^\phi_{qns}\in\Z^N$ which minimizes $\abs{E_{qns}-E_\phi-\v\ell^\phi_{qns}\c\v\nu}$, and define the reduced energy \begin{align} \epsilon_{qns}^\phi \equiv E_{qns} - E_\phi - \v\ell^\phi_{qns}\c\v\nu, && \t{such that} && E_{qns} = E_\phi + \v\ell^\phi_{qns}\c\v\nu + \epsilon_{qns}^\phi. \end{align} We can then expand \begin{align} E_{qm\bar s} - E_{qns} - \v k^{qs}_{nm}\c\v\nu = \p{\v\ell^\phi_{qm\bar s} - \v\ell^\phi_{qns} - \v k^{qs}_{nm}}\c\v\nu + \epsilon_{qm\bar s}^\phi - \epsilon_{qns}^\phi. \label{eq:k_min} \end{align} From their definition, the reduced energies satisfy $\abs{\epsilon_{qm\bar s}^\phi}, \abs{\epsilon_{qns}^\phi} < \min_j\nu_j/2$. If we make a stronger assumption that $\abs{\epsilon_{qm\bar s}^\phi}, \abs{\epsilon_{qns}^\phi} < \min_j\nu_j/4$, then $\abs{\epsilon_{qm\bar s}^\phi - \epsilon_{qns}^\phi} < \min_j\nu_j/2$, so minimizing the quantity in \eqref{eq:k_min} forces $\v k^{qs}_{nm} = \v\ell^\phi_{qm\bar s} - \v\ell^\phi_{qns}$, which implies \begin{align} H_I = -\f12\sum_{q,n,s,m} f\p{\v k^{qs}_{nm},\v\beta,\v\phi} \Omega^{qs}_{nm} \exp\sp{i\p{\epsilon_{qm\bar s}^\phi-\epsilon_{qns}^\phi}t} b_{qm\bar s}^\dag b_{qns}. \end{align} In an appropriate interaction picture this Hamiltonian is equivalent to \begin{align} H_I^{\t{eff}} = \sum_{q,n,s} \epsilon_{qns}^\phi b_{qns}^\dag b_{qns} - \f12\sum_{q,n,s,m} f\p{\v k^{qs}_{nm},\v\beta,\v\phi} \Omega^{qs}_{nm} b_{qm\bar s}^\dag b_{qns}. \end{align} \section{Interactions} The interaction Hamiltonian for fermionic AEAs on a lattice is \begin{align} H_{\t{int}} = G \int d^3x~ \psi_\e^\dag\p{x} \psi_\g^\dag\p{x} \psi_\g\p{x} \psi_\e\p{x}, && G \equiv \f{4\pi a_{\e\g^-}}{m_A}. \end{align} Expanding the field operators for atoms in clock state $\sigma$ as \begin{align} \psi_\sigma\p{x} = \sum_{q,n} \phi_{qn}\p{x} c_{qn\sigma}, \end{align} for quasimomenta $q$ and band indices $n$, we can write \begin{align} H_{\t{int}} = G \sum K^{pk;q\ell}_{rm;sn} c_{rm,\e}^\dag c_{sn,\g}^\dag c_{q\ell,\g} c_{pk,\e}, && K^{pk;q\ell}_{rm;sn} \equiv \int d^3x~ \phi_{rm}\p{x}^* \phi_{sn}\p{x}^* \phi_{q\ell}\p{x} \phi_{pk}\p{x}. \end{align} By conservation of momentum, we know that $K^{pk;q\ell}_{rm;sn}=0$ unless $p+q+r+s=0$ ($\t{mod}~2$ in units of the lattice wavenumber), so we can write \begin{align} H_{\t{int}} = G \sum K^{pk;q\ell}_{p+r,m;q-r,n} c_{p+r,m,\e}^\dag c_{q-r,n,\g}^\dag c_{q\ell,\g} c_{pk,\e} \approx G \sum K^{k\ell}_{mn} c_{p+r,m,\e}^\dag c_{q-r,n,\g}^\dag c_{q\ell,\g} c_{pk,\e}, \end{align} where we made the approximation that $K^{pk;q\ell}_{p+r,m;q-r,n}$ only weakly depends on the quasi-momenta $\p{p,q,r}$. \subsection{Single-band spin model} We now restrict ourselves to considering only the lowest band, such that $K^{k\ell}_{mn}\to K$ and the single-particle energy takes the form $E_q=-4J\cos\p{\pi q}$. If $J \gg G K$, then by the secular approximation we can neglect terms in $H_{\t{int}}$ which do not conserve the sum of single-particle energies. By solving the single-particle energy conservation condition, one can find that this approximation amounts to neglecting terms with $r\notin\set{0,q-p}$, such that \begin{align} H_{\t{int}} = G K \sum \p{n_{q,\g} n_{p,\e} + c_{q,\e}^\dag c_{p,\g}^\dag c_{q,\g} c_{p,\e}} = G K \sum \p{n_{q,\g} n_{p,\e} - c_{q,\e}^\dag c_{q,\g} c_{p,\g}^\dag c_{p,\e}}. \end{align} Defining \begin{align} \1_p \equiv c_{p,\e}^\dag c_{p,\e} + c_{p,\g}^\dag c_{p,\g}, && \sigma_p^j \equiv \sum_{\alpha,\beta} c_{p\alpha}^\dag \sigma^j_{\alpha\beta} \sigma_{p\beta}, \end{align} for Pauli matrices $\sigma^j$, we can therefore write \begin{align} H_{\t{int}} = G K \sum \sp{\p{\f{\1_q+\sigma_q^z}{2}} \p{\f{\1_p-\sigma_p^z}{2}} - \sigma_q^- \sigma_p^+}. \end{align} Up to a global shift in energy, this result is equivalently \begin{align} H_{\t{int}} = - \f14 G K \sum \v\sigma_q\c\v\sigma_p = - \f14 G K \v\sigma \c \v\sigma = - G K \v S \c \v S, && \v S \equiv \f12 \v\sigma. \end{align} Expanding \begin{align} K = \int d^3x \abs{\phi_0}^4 = \int d^3x \abs{\f1{\sqrt{N}}\sum_j\tilde\phi_j}^4 \approx \f1{N^2} \sum_j \int d^3x \abs{\tilde\phi_j}^4 = \f1N \int d^3x \abs{\tilde\phi_0}^4 = \f1N \tilde K, \end{align} we therefore arrive at the Hamiltonian \begin{align} H_{\t{int}} = - \f{G\tilde K}{N} \v S\c\v S = -\f{\xi}{N} \v S\c\v S, && \xi \equiv G \tilde K. \end{align} \subsection{Inter-band pair hopping} We now consider pair hopping between the lowest two bands, and define $a_{p\sigma} \equiv c_{p,0,\sigma}$ and $b_{p\sigma} \equiv c_{p,1,\sigma}$. The relevant terms in the Hamiltonian are \begin{align} H_{\t{int}}^{(0,1)} = G K^{0,0}_{1,1} \sum \p{b_{p+r,\e}^\dag b_{q-r,\g}^\dag a_{q,\g} a_{p,\e} + \t{h.c.}}. \end{align} Using driving schemes, we can make the single-particle energies in the first two bands respectively $E_{q,0}=-4J_0\cos\p{\pi q}$ and $E_{q,1}=4J_1\cos\p{\pi q}$. As in the single-band case, we now assume that we can neglect hopping terms in $H_{\t{int}}^{(0,1)}$ which do not conserve single-particle energy. By solving this energy conservation condition in the limit $\abs{J_1}\gg\abs{J_0}$, we find that the only terms which survive are those with $r=r_\pm\equiv-\p{p-q}/2\pm1/2$. Defining \begin{align} s \equiv \f{p+q}{2}, && d \equiv \f{p-q}{2}, \end{align} in terms of which \begin{align} p = s + d, && q = s - d, && r_\pm = -d \pm 1/2, \end{align} we can write \begin{align} H_{\t{int}}^{(0,1)} = \sqrt{2} G K^{0,0}_{1,1} \sum \p{f_s^\dag a_{s-d,\g} a_{s+d,\e} + \t{h.c.}} = \sqrt{2} G K^{0,0}_{1,1} \sum \p{f_{\p{p+q}/2}^\dag a_{q,\g} a_{p,\e} + \t{h.c.}}, \end{align} where \begin{align} f_s^\dag \equiv \f1{\sqrt2} \p{b_{s-1/2,\e}^\dag b_{s+1/2,\g}^\dag + b_{s+1/2,\e}^\dag b_{s-1/2,\g}^\dag}. \end{align} For $r\ne s$, these operators satisfy the commutation relations \begin{align} \sp{f_r, f_s} = \sp{f_r^\dag, f_s^\dag} = \sp{f_r, f_s^\dag} = 0, \end{align} \begin{align} \sp{f_s, f_s^\dag} = 1 - \f12 \p{\tilde n_{s+1/2,\e}^\dag + \tilde n_{s-1/2,\e}^\dag + \tilde n_{s+1/2,\g}^\dag + \tilde n_{s-1/2,\g}^\dag}, && \tilde n_{p\sigma} \equiv b_{p\sigma}^\dag b_{p\sigma}. \end{align} \end{document}
% Options for packages loaded elsewhere \PassOptionsToPackage{unicode}{hyperref} \PassOptionsToPackage{hyphens}{url} % \documentclass[ ]{book} \usepackage{lmodern} \usepackage{amssymb,amsmath} \usepackage{ifxetex,ifluatex} \ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage{textcomp} % provide euro and other symbols \else % if luatex or xetex \usepackage{unicode-math} \defaultfontfeatures{Scale=MatchLowercase} \defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1} \fi % Use upquote if available, for straight quotes in verbatim environments \IfFileExists{upquote.sty}{\usepackage{upquote}}{} \IfFileExists{microtype.sty}{% use microtype if available \usepackage[]{microtype} \UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts }{} \makeatletter \@ifundefined{KOMAClassName}{% if non-KOMA class \IfFileExists{parskip.sty}{% \usepackage{parskip} }{% else \setlength{\parindent}{0pt} \setlength{\parskip}{6pt plus 2pt minus 1pt}} }{% if KOMA class \KOMAoptions{parskip=half}} \makeatother \usepackage{xcolor} \IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available \IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}} \hypersetup{ pdftitle={An Introduction to Probability and Simulation}, pdfauthor={Kevin Ross}, hidelinks, pdfcreator={LaTeX via pandoc}} \urlstyle{same} % disable monospaced font for URLs \usepackage{color} \usepackage{fancyvrb} \newcommand{\VerbBar}{|} \newcommand{\VERB}{\Verb[commandchars=\\\{\}]} \DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}} % Add ',fontsize=\small' for more characters per line \usepackage{framed} \definecolor{shadecolor}{RGB}{248,248,248} \newenvironment{Shaded}{\begin{snugshade}}{\end{snugshade}} \newcommand{\AlertTok}[1]{\textcolor[rgb]{0.94,0.16,0.16}{#1}} \newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}} \newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.77,0.63,0.00}{#1}} \newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}} \newcommand{\BuiltInTok}[1]{#1} \newcommand{\CharTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}} \newcommand{\CommentTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}} \newcommand{\CommentVarTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}} \newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}} \newcommand{\ControlFlowTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}} \newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{#1}} \newcommand{\DecValTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}} \newcommand{\DocumentationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}} \newcommand{\ErrorTok}[1]{\textcolor[rgb]{0.64,0.00,0.00}{\textbf{#1}}} \newcommand{\ExtensionTok}[1]{#1} \newcommand{\FloatTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}} \newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}} \newcommand{\ImportTok}[1]{#1} \newcommand{\InformationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}} \newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}} \newcommand{\NormalTok}[1]{#1} \newcommand{\OperatorTok}[1]{\textcolor[rgb]{0.81,0.36,0.00}{\textbf{#1}}} \newcommand{\OtherTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{#1}} \newcommand{\PreprocessorTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}} \newcommand{\RegionMarkerTok}[1]{#1} \newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}} \newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}} \newcommand{\StringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}} \newcommand{\VariableTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}} \newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}} \newcommand{\WarningTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}} \usepackage{longtable,booktabs} % Correct order of tables after \paragraph or \subparagraph \usepackage{etoolbox} \makeatletter \patchcmd\longtable{\par}{\if@noskipsec\mbox{}\fi\par}{}{} \makeatother % Allow footnotes in longtable head/foot \IfFileExists{footnotehyper.sty}{\usepackage{footnotehyper}}{\usepackage{footnote}} \makesavenoteenv{longtable} \usepackage{graphicx} \makeatletter \def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi} \def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi} \makeatother % Scale images if necessary, so that they will not overflow the page % margins by default, and it is still possible to overwrite the defaults % using explicit options in \includegraphics[width, height, ...]{} \setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio} % Set default figure placement to htbp \makeatletter \def\fps@figure{htbp} \makeatother \setlength{\emergencystretch}{3em} % prevent overfull lines \providecommand{\tightlist}{% \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}} \setcounter{secnumdepth}{5} \usepackage{booktabs} \usepackage{amsthm} \makeatletter \def\thm@space@setup{% \thm@preskip=8pt plus 2pt minus 4pt \thm@postskip=\thm@preskip } \makeatother \usepackage[]{natbib} \bibliographystyle{apalike} \title{An Introduction to Probability and Simulation} \author{Kevin Ross} \date{2020-07-11} \usepackage{amsthm} \newtheorem{theorem}{Theorem}[chapter] \newtheorem{lemma}{Lemma}[chapter] \newtheorem{corollary}{Corollary}[chapter] \newtheorem{proposition}{Proposition}[chapter] \newtheorem{conjecture}{Conjecture}[chapter] \theoremstyle{definition} \newtheorem{definition}{Definition}[chapter] \theoremstyle{definition} \newtheorem{example}{Example}[chapter] \theoremstyle{definition} \newtheorem{exercise}{Exercise}[chapter] \theoremstyle{remark} \newtheorem*{remark}{Remark} \newtheorem*{solution}{Solution} \begin{document} \maketitle { \setcounter{tocdepth}{1} \tableofcontents } \hypertarget{preface}{% \chapter*{Preface}\label{preface}} \addcontentsline{toc}{chapter}{Preface} \newcommand{\IP}{\textrm{P}} \newcommand{\IQ}{\textrm{Q}} \newcommand{\E}{\textrm{E}} \newcommand{\Var}{\textrm{Var}} \newcommand{\SD}{\textrm{SD}} \newcommand{\Cov}{\textrm{Cov}} \newcommand{\Corr}{\textrm{Corr}} \newcommand{\Xbar}{\bar{X}} \newcommand{\Ybar}{\bar{X}} \newcommand{\xbar}{\bar{x}} \newcommand{\ybar}{\bar{y}} \newcommand{\ind}{\textrm{I}} \newcommand{\dd}{\text{DDWDDD}} \newcommand{\ep}{\epsilon} \newcommand{\reals}{\mathbb{R}} \hypertarget{why-study-probability-and-simulation}{% \subsection*{\texorpdfstring{Why study probability \emph{and simulation}?}{Why study probability and simulation?}}\label{why-study-probability-and-simulation}} \addcontentsline{toc}{subsection}{Why study probability \emph{and simulation}?} Why study probability? \begin{itemize} \tightlist \item Probability is the study of uncertainty, and life is uncertain \item Probability is used in a wide variety of fields, including: \href{https://fivethirtyeight.com/features/not-even-scientists-can-easily-explain-p-values/}{statistics}, \href{https://www.ucdavis.edu/news/does-probability-come-quantum-physics/}{physics}, \href{https://en.wikipedia.org/wiki/Signal_processing}{engineering}, \href{https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3843941/}{biology}, \href{https://cvi.asm.org/content/cdli/23/4/249.full.pdf}{medicine}, \href{https://www.marketwatch.com/story/the-4-called-the-last-financial-crisis-heres-what-they-see-causing-the-next-one-2018-09-13}{finance}, \href{https://www.ssa.gov/oact/STATS/table4c6.html}{actuarial science}, \href{https://projects.fivethirtyeight.com/2016-election-forecast/}{political science}, \href{https://en.wikipedia.org/wiki/Prosecutor\%27s_fallacy}{law}, \href{https://www.numberfire.com/nfl/lists/18685/the-10-biggest-plays-of-super-bowl-lii}{sports} , \ldots{} \item Many topics and problems in probability are frequently misunderstood and sometimes counter intuitive, so it's worthwhile to take a careful study \item ``Probabilistic thinking'' is an important component of statistical literacy (e.g.~how to assess risk when making decisions) \item Probability provides the foundation for many important statistical concepts and methods such as p-values and confidence intervals \end{itemize} Why use \textbf{simulation} to study probability? \begin{itemize} \tightlist \item Many concepts encountered in probability can seem esoteric; simulation helps make them more concrete. \item Simulation provides an effective tool for analyzing probability models and for exploring effects of changing assumptions \item Simulation can be used to check analytical solutions \item Simulation is often the best or only method for investigating many problems which are too complex to solve analytically \item Simulation-based reasoning is an important component of statistical literacy (e.g.~understanding a p-value via simulation) \item Many statistical procedures employ simulation-based methods (e.g.~bootstrapping) \end{itemize} \hypertarget{learning-objectivesgoalsstyle-better-title}{% \subsection{Learning Objectives/Goals/Style??? (Better title)}\label{learning-objectivesgoalsstyle-better-title}} \begin{itemize} \tightlist \item Don't skimp on rigorous definitions (RV is function defined on probspace) but deemphasize mathematical computation (counting and calculus) \item Emphasize simulation \item Visualize in lots of plots \item Start multivariate relationships early \item Rely on statistical literacy \item Active learning, workbook style \end{itemize} \hypertarget{symbulate}{% \subsection*{Symbulate}\label{symbulate}} \addcontentsline{toc}{subsection}{Symbulate} This book uses the Python package Symbulate (\url{https://github.com/dlsun/symbulate}) which provides a user friendly framework for conducting simulations involving probability models. The syntax of Symbulate reflects the ``language of probability'' and makes it intuitive to specify, run, analyze, and visualize the results of a simulation. In Symbulate, probability spaces, events, random variables, and random processes are symbolic objects which can be manipulated, independently of their simulated realizations. Symbulate's consistency with the mathematics of probability reinforces understanding of probabilistic concepts. The article \citet{symbulateJSE} discusses Symbulate and its features in more detail. To install Symbulate, it is recommended that you first install the \href{https://www.anaconda.com/distribution/}{Anaconda distribution}, which is a Python environment with many scientific packages installed (including all of the packages that Symbulate is built on). After installing Anaconda, the recommended way to installing Symbulate is run the command \begin{verbatim} !pip install symbulate \end{verbatim} from inside a notebook. (The Symbulate package can also be downloaded and installed manually from the \href{/href\%7Bhttps://github.com/dlsun/symbulate\%7D}{Symbulate Github repository} following these \href{https://web.calpoly.edu/~dsun09/python.html}{instructions}.) The following command imports Symbulate during a Python session. \begin{Shaded} \begin{Highlighting}[] \ImportTok{from}\NormalTok{ symbulate }\ImportTok{import} \OperatorTok{*} \end{Highlighting} \end{Shaded} The Symbulate command \texttt{plot()} produces graphics. These graphics can be customized (by changing axis limits, adding titles, legends, etc) using Matplotlib, and in particular the \texttt{pyplot} method, which can be imported with \begin{verbatim} import matplotlib import matplotlib.pyplot as plt \end{verbatim} \href{http://jupyter.org/}{Jupyter} or \href{https://colab.research.google.com/notebooks/intro.ipynb\#}{Google Colab} notebooks provide a natural interface for Symbulate. The code in this book matches as closely as possible the commands that would be entered into cells in a notebook. However, certain commands that appear throughout the book are needed only to properly produce the output in this book, and not if working directly in notebooks. In particular, \texttt{plt.figure()} and \texttt{plt.show()} are not needed to produce graphics in Jupyter (with the use of the \texttt{\%matplotlib\ inline} ``magic''). In addition, Jupyter automatically displays the result of the last line in a cell; \texttt{print()} is generally not needed to display output (unless you wish to format it, or it is not the last line in the cell). For example, a code snippet that appears in this book as \begin{Shaded} \begin{Highlighting}[] \NormalTok{x }\OperatorTok{=}\NormalTok{ RV(Binomial(}\DecValTok{4}\NormalTok{, }\FloatTok{0.5}\NormalTok{)).sim(}\DecValTok{10000}\NormalTok{)} \NormalTok{plt.figure()} \NormalTok{x.plot()} \NormalTok{plt.show()} \BuiltInTok{print}\NormalTok{(x)} \end{Highlighting} \end{Shaded} \begin{Shaded} \begin{Highlighting}[] \NormalTok{x }\OperatorTok{=}\NormalTok{ RV(Binomial(}\DecValTok{4}\NormalTok{, }\FloatTok{0.5}\NormalTok{)).sim(}\DecValTok{10000}\NormalTok{)} \CommentTok{\# plt.figure()} \NormalTok{x.plot()} \NormalTok{plt.show()} \end{Highlighting} \end{Shaded} \includegraphics{bookdown-demo_files/figure-latex/unnamed-chunk-5-1.pdf} \begin{Shaded} \begin{Highlighting}[] \BuiltInTok{print}\NormalTok{(x)} \end{Highlighting} \end{Shaded} \begin{verbatim} ## <symbulate.results.RVResults object at 0x000000001D146CC8> \end{verbatim} \begin{Shaded} \begin{Highlighting}[] \NormalTok{x }\OperatorTok{=}\NormalTok{ RV(Binomial(}\DecValTok{4}\NormalTok{, }\FloatTok{0.5}\NormalTok{)).sim(}\DecValTok{10000}\NormalTok{)} \NormalTok{plt.figure()} \NormalTok{x.plot()} \NormalTok{plt.show()} \end{Highlighting} \end{Shaded} \includegraphics{bookdown-demo_files/figure-latex/unnamed-chunk-6-1.pdf} \begin{Shaded} \begin{Highlighting}[] \BuiltInTok{print}\NormalTok{(x)} \end{Highlighting} \end{Shaded} \begin{verbatim} ## <symbulate.results.RVResults object at 0x000000001C307F48> \end{verbatim} would be entered in a Jupyter notebook as \begin{Shaded} \begin{Highlighting}[] \NormalTok{x }\OperatorTok{=}\NormalTok{ RV(Binomial(}\DecValTok{4}\NormalTok{, }\FloatTok{0.5}\NormalTok{)).sim(}\DecValTok{10000}\NormalTok{)} \NormalTok{x.plot()} \NormalTok{x} \end{Highlighting} \end{Shaded} \hypertarget{dont-do-what-donny-dont-does}{% \subsection*{Don't do what Donny Don't does}\label{dont-do-what-donny-dont-does}} \addcontentsline{toc}{subsection}{Don't do what Donny Don't does} Some of the examples and exercises in this book are labeled ``Don't do what Donny Don't does''. This is a \href{https://frinkiac.com/video/S05E08/0nvMY69o6o_U7BqeIzQ314al-SQ=.gif}{Simpson's} \href{https://www.youtube.com/watch?v=pbwxlyUunL8}{reference}. In this text, Donny represents a student who makes many of the mistakes commonly made by students studying probability. The idea of these problems is for you to learn from the common mistakes that Donny makes, by identifying why he is wrong and by helping him understand and correct his mistakes. (But be careful: sometimes Donny is right!) \hypertarget{about-this-book}{% \subsection*{About this book}\label{about-this-book}} \addcontentsline{toc}{subsection}{About this book} This book was written using the \textbf{bookdown} package \citep{R-bookdown}, which was built on top of R Markdown and \textbf{knitr} \citep{xie2015}. Python code was run in RStudio using the \texttt{reticulate} package. \hypertarget{intro}{% \chapter{Introduction}\label{intro}} You can label chapter and section titles using \texttt{\{\#label\}} after them, e.g., we can reference Chapter \ref{intro}. If you do not manually label them, there will be automatic labels anyway, e.g., Chapter \ref{methods}. Figures and tables with captions will be placed in \texttt{figure} and \texttt{table} environments, respectively. \begin{Shaded} \begin{Highlighting}[] \KeywordTok{par}\NormalTok{(}\DataTypeTok{mar =} \KeywordTok{c}\NormalTok{(}\DecValTok{4}\NormalTok{, }\DecValTok{4}\NormalTok{, }\FloatTok{.1}\NormalTok{, }\FloatTok{.1}\NormalTok{))} \KeywordTok{plot}\NormalTok{(pressure, }\DataTypeTok{type =} \StringTok{\textquotesingle{}b\textquotesingle{}}\NormalTok{, }\DataTypeTok{pch =} \DecValTok{19}\NormalTok{)} \end{Highlighting} \end{Shaded} \begin{figure} {\centering \includegraphics[width=0.8\linewidth]{bookdown-demo_files/figure-latex/nice-fig-1} } \caption{Here is a nice figure!}\label{fig:nice-fig} \end{figure} Reference a figure by its code chunk label with the \texttt{fig:} prefix, e.g., see Figure \ref{fig:nice-fig}. Similarly, you can reference tables generated from \texttt{knitr::kable()}, e.g., see Table \ref{tab:nice-tab}. \begin{Shaded} \begin{Highlighting}[] \NormalTok{knitr}\OperatorTok{::}\KeywordTok{kable}\NormalTok{(} \KeywordTok{head}\NormalTok{(iris, }\DecValTok{20}\NormalTok{), }\DataTypeTok{caption =} \StringTok{\textquotesingle{}Here is a nice table!\textquotesingle{}}\NormalTok{,} \DataTypeTok{booktabs =} \OtherTok{TRUE} \NormalTok{)} \end{Highlighting} \end{Shaded} \begin{table} \caption{\label{tab:nice-tab}Here is a nice table!} \centering \begin{tabular}[t]{rrrrl} \toprule Sepal.Length & Sepal.Width & Petal.Length & Petal.Width & Species\\ \midrule 5.1 & 3.5 & 1.4 & 0.2 & setosa\\ 4.9 & 3.0 & 1.4 & 0.2 & setosa\\ 4.7 & 3.2 & 1.3 & 0.2 & setosa\\ 4.6 & 3.1 & 1.5 & 0.2 & setosa\\ 5.0 & 3.6 & 1.4 & 0.2 & setosa\\ \addlinespace 5.4 & 3.9 & 1.7 & 0.4 & setosa\\ 4.6 & 3.4 & 1.4 & 0.3 & setosa\\ 5.0 & 3.4 & 1.5 & 0.2 & setosa\\ 4.4 & 2.9 & 1.4 & 0.2 & setosa\\ 4.9 & 3.1 & 1.5 & 0.1 & setosa\\ \addlinespace 5.4 & 3.7 & 1.5 & 0.2 & setosa\\ 4.8 & 3.4 & 1.6 & 0.2 & setosa\\ 4.8 & 3.0 & 1.4 & 0.1 & setosa\\ 4.3 & 3.0 & 1.1 & 0.1 & setosa\\ 5.8 & 4.0 & 1.2 & 0.2 & setosa\\ \addlinespace 5.7 & 4.4 & 1.5 & 0.4 & setosa\\ 5.4 & 3.9 & 1.3 & 0.4 & setosa\\ 5.1 & 3.5 & 1.4 & 0.3 & setosa\\ 5.7 & 3.8 & 1.7 & 0.3 & setosa\\ 5.1 & 3.8 & 1.5 & 0.3 & setosa\\ \bottomrule \end{tabular} \end{table} You can write citations, too. For example, we are using the \textbf{bookdown} package \citep{R-bookdown} in this sample book, which was built on top of R Markdown and \textbf{knitr} \citep{xie2015}. \hypertarget{prob-literacy}{% \chapter{What is Probability?}\label{prob-literacy}} This chapter provides a non-technical introduction to randomness and probability. Many of the topics introduced in this chapter will be covered in more detail in later chapters. NO MATH BEYOND TWO WAY TABLES AND BASIC EXPECTED VALUES Expand chapter 1 with more example of probability/simulation computations with as little math and terminology as possible. (e.g.~Don't define RV or event or sample space.) Add a few motivating examples with links - 538 election, hurricane, etc \hypertarget{randomness}{% \section{Instances of randomness}\label{randomness}} instances of randomness - examples; include in other sections? (random sampling, random assignment, future/past, etc, physical (coin, die), quantum) \begin{exercise} \protect\hypertarget{exr:randomness}{}{\label{exr:randomness} } Each of the following situations involves a probability. How are the various situations similar, and how are they different? What is one feature that all of the situations have in common? If you were to estimate the probability in question, how might you do it? What are some things to consider? The goal here is not to do any calculations but rather to think about, via these examples, similarities and differences of situations in which probabilities are of interest. \end{exercise} \begin{enumerate} \def\labelenumi{\arabic{enumi}.} \tightlist \item The probability that a single flip of a fair coin lands on heads. \item The probability that in two flips of a fair coin exactly one flip lands on heads. \item The probability that in 10000 flips of a fair coin exactly 5000 flips land on heads. \item The probability that in 10000 flips of a fair coin ``around'' 5000 flips land on heads. \item The probability you win the next \href{https://www.powerball.com/}{Powerball lottery} if you purchase a single ticket, 6-7-16-23-26, plus the Powerball number, 4. (FYI: There are roughly\footnote{The exact count is 292,201,338. We will see how to compute this number later.} 300 million possible winning number combinations.) \item The probability you win the next Powerball lottery if you purchase a single ticket, 1-2-3-4-5, plus the Powerball number, 6. \item The probability that someone wins the next Powerball lottery. (FYI: especially when the jackpot is large, there are hundreds of millions of tickets sold.) \item The probability that a ``randomly selected'' Cal Poly student is from CA.\\ \item The probability that Hurricane Humberto makes landfall in the U.S. \item The probability that the Los Angeles Chargers win the next Superbowl. \item The probability that Donald Trump wins the 2020 U.S. Presidential Election. \item The probability that extraterrestrial life currently exists somewhere in the universe. \item The probability that you ate an apple on April 17, 2009. \end{enumerate} \begin{itemize} \tightlist \item The subject of probability concerns \emph{random} phenomena. \item A phenomenon is \textbf{random} if there are multiple potential outcomes, and there is \textbf{uncertainty} about which outcome will occur. \emph{Uncertainty} is the feature that all the scenarios have in common. \item Uncertainty does not necessarily mean uncertainty about an occurrence in the future. For example, you either ate or apple or not on April 17, 2009, but you're not certain about it. But if you tended to eat a lot of apples ten years ago, then you might give a high probability to the event that you ate one on April 17, 2009. \item Many phenomena involve physical randomness\footnote{We will refer to as ``random'' any scenario that involves a reasonable degree of uncertainty. We're avoiding philosophical questions about what is ``true'' randomness, like the following. Is a coin flip really random? If all factors that affect the trajectory of the coin were known precisely, then wouldn't the outcome be determined? Does true randomness only exist in quantum mechanics?}, like flipping a coin or drawing powerballs at random from a bin. \item Statistical applications often involve the planned use of physical randomness \begin{itemize} \tightlist \item \textbf{Random selection} involves selecting a \emph{sample} of individuals at random from a \emph{population} (e.g.~via random digit dialing). \item \textbf{Random assignment} involves assigning individuals at random to groups (e.g.~in a randomized experiment). \end{itemize} \item However, in many other situations randomness just vaguely reflects uncertainty. \item In any case, random does \emph{not} mean haphazard. In a random phenomenon, while individual outcomes are uncertain, there is a \emph{regular distribution of outcomes over a large number of (hypothetical) repetitions}. \begin{itemize} \tightlist \item In two flips of a fair coin we wouldn't necessarily see one head and one tail. But in 10000 flips of a fair coin, we would expect to see close to 5000 heads and 5000 tails. \item We don't know who will win the next Superbowl, but we can and should certainly consider some teams as more likely to win than others. We could imagine a large number of hypothetical 2019 seasons; how often would we expect the Eagles to win? The Raiders? (Hopefully a lot for the Eagles; probably not much for the Raiders). \end{itemize} \item Also, random does \emph{not} necessarily mean equally likely. In a random phenomenon, certain outcomes or events might be more or less likely than others. \begin{itemize} \tightlist \item It's much more likely that a randomly selected Cal Poly student is from CA than not. \item Not all NFL teams are equally likely to win the next Superbowl. \end{itemize} \end{itemize} \hypertarget{interpretations}{% \section{Interpretations of probability}\label{interpretations}} In the previous section we encountered a variety of scenarios which involved uncertainty, a.k.a. randomness. Just as there are a few ``types'' of randomness, there are a few ways of interpreting probability, namely, \emph{long run relative frequency} and \emph{subjective probability}. \begin{exercise} \protect\hypertarget{exr:probability-intepret}{}{\label{exr:probability-intepret} } Revisit the scenarios in Exercise \ref{exr:randomness}. Now consider how ``probability'' is interpreted in the different scenarios. In each scenario, what does ``probability'' mean? How might you estimate the probability? Start to make guesses for the probabilities; are they ``high'' or ``low''? How high or low? Again, the goal is not to do any calculations but rather to think about, via these examples, similarities and differences of situations in which probabilities are of interest. \end{exercise} In particular, compare \begin{enumerate} \def\labelenumi{\alph{enumi}.} \tightlist \item Scenarios 3 and 4 \item Scenarios 5 and 6 \item Scenarios 6 and 7 \item How are scenarios 1 through 8 (collectively) different from scenarios 9 through 13 (collectively)? \end{enumerate} \begin{itemize} \tightlist \item The \textbf{probability} of an event is a number in the interval \([0, 1]\) measuring the event's likelihood or degree of uncertainty. \item A probability can take any values in the continuous scale from 0\% to 100\%\footnote{Probabilities are usually defined as decimals, but are often colloquially referred to as percentages. We're not sticklers; we'll refer to probabilities as decimals and as percentages.}. In particular, a probability requires much more interpretation than ``is the probability greater than, less than, or equal to 50\%?'' \item When interpreting probabilities, be careful not to confuse ``the particular'' with ``the general''. \begin{itemize} \tightlist \item (``The particular.'') A very specific event, surprising or not, often has low probability. \begin{itemize} \tightlist \item Even though in 10000 flips of a fair coin we would expect to see about 5000 heads, the probability that \emph{exactly} 5000 out of 10000 flips are heads is fairly small (about\footnote{We will see how to compute probabilities like this one in upcoming chapters.} 0.008). \item The probability that the winning powerball number is 6-7-16-23-26-(4) is exactly the same as the probability that the winning powerball number is 1-2-3-4-5-(6). Each of these sequences is just one of the roughly 300 million possible sequences, and each sequences has about a 1 in 300 million chance of being the winning number. However, many people think 6-7-16-23-26-(4) is more likely because 1-2-3-4-5-(6) ``doesn't look random''. \item The probability that you get a text from your best friend at 7:43pm on Oct 12, 2019 inviting you to dinner after you've just ordered pizza from your favorite pizza place is probably pretty small. None of these items --- getting a text, having a friend invite you to dinner, ordering pizza from your favorite pizza place --- is unusual, but the chances of them all combining in this way at this particular time are fairly small. \end{itemize} \item (``The general.'') However, if there are many like events, their combined probability can be high. \begin{itemize} \tightlist \item The probability that \emph{around} 5000 out of 10000 coin flips land on heads is fairly large. For example, if ``around'' is interpreted as between 4900 and 5100 (for a proportion of heads between 0.49 to 0.51) the probability is about 0.956. \item The probability that the winning powerball number is an ordered sequence, like 1-2-3-4-5-(6), is extremely small\footnote{If a ``sequence'' is defined with the powerball as the last number in the sequence, then the probability is about 21 out of 300 million. Since the powerball must be a number from 1 to 26, there are only 21 tickets out of 300 million possibilities for which the numbers are in an ordered sequence: 1-2-3-4-5-(6), 2-3-4-5-6-(7), \ldots{} 21-22-23-24-25-(26).}. However, the probability that the winning number is not an ordered sequence, like 6-7-16-23-26-(4), is exremely high. When interpreting probabilities, be careful not to confuse an event like ``the winning number is 6-7-16-23-26-(4)'' (the particular, low probability) with an event like ``the winning number is not an ordered sequence'' (the general, high probability).\\ \item The probability that some time in the next month or so a friend invites you for dinner after you've already had dinner on your own is probably fairly high. \end{itemize} \end{itemize} \item Even if an event has extremely small probability, given enough repetitions of the random phenomenon, the probability that the event occurs on \emph{at least one} of the repetitions is high. \begin{itemize} \tightlist \item The probability that a specific powerball ticket is the winning number is about 1 in 300 million. So if you buy a single ticket, it is \href{https://www.huffpost.com/entry/chances-of-winning-powerball-lottery_b_3288129}{extremely unlikely} that \emph{you} will win. \item However, if hundreds of millions of powerball tickets are sold, the probability that \emph{someone somewhere} wins is pretty high. For example, if 500 million tickets are sold then there is a roughly 80\% chance that at least one ticket has the winning number (under \href{https://fivethirtyeight.com/features/new-powerball-odds-could-give-america-its-first-billion-dollar-jackpot/}{certain assumptions}). \end{itemize} \end{itemize} \hypertarget{rel-freq}{% \subsection{Relative frequency}\label{rel-freq}} The probability that a single flip of a fair coin lands on heads is 0.5. How do we interpret this 0.5? The notation of ``fairness'' implies that the two outcomes, heads and tails, should be equally likely, so we have a ``50/50 chance''. But how else can we interpret this 50\%? One way is by considering \emph{what would happen if we flipped the coin main times}. Now, if we would flipped the coin twice, we wouldn't expect to necessarily see one head and one tail. And we already mentioned that if we flipped the coin 10000 times, the chances of seeing \emph{exactly} 5000 heads is small. But in many flips, we might expect to see heads on something close to 50\% of flips. Consider Figure \ref{fig:coin-sim1} below. Each dot represents a set of 10,000 fair coin flips. There are 100 dots displayed, representing 100 different sets of 10,000 coin flips each. For each set of flips, the proportion of the 10,000 flips which landed on head is recorded. For example, if in one set 4973 out of 10,000 flips landed on heads, the proportion of heads is 0.4973. The plot displays 100 such proportions. We see that only 5 of these 100 proportions are less than 0.49 or greater than 0.51. So if between 0.49 and 0.51 is considered ``close to 0.5'', then yes, in 10000 coin flips we would expect the proportion of heads to be close to 0.5. (In 10000 flips, the probability of heads on between 49\% and 51\% of flips is 0.956, so 95 out of 100 provides a rough estimate of this probability.) \begin{figure} \includegraphics[width=8.65in]{_graphics/coin-sim1} \caption{Proportion of flips which are heads in 100 sets of \textbf{10,000} fair coin flips. Each dot represents a set of \textbf{10,000} fair coin flips.}\label{fig:coin-sim1} \end{figure} But what if we want to be stricter about what qualifies as ``close to 0.5''? You might suspect that with even more flips we would expect to observe heads on even closer to 50\% of flips. Indeed, this is the case. Figure \ref{fig:coin-sim2} displays the results of 100 sets of 1,000,000 fair coin flips. The pattern seems similar to Figure \ref{fig:coin-sim1} but pay close attention to the horizontal axis which covers a much shorter range of values than in the previous figure. Now 96 of the 100 proportions are between 0.499 and 0.501. So in 1,000,000 flips we would expect the proportion of heads to be between 0.499 and 0.501, pretty close to 0.5. (In 1,000,000 flips, the probability of heads on between 49.9\% and 50.1\% of flips is 0.955, and 96 out of 100 sets provides a rough estimate of this probability.) \begin{figure} \includegraphics[width=8.65in]{_graphics/coin-sim2} \caption{Proportion of flips which are heads in 100 sets of \textbf{1,000,000} fair coin flips. Each dot represents a set of \textbf{1,000,000} fair coin flips.}\label{fig:coin-sim2} \end{figure} In Figure \ref{fig:coin-sim3} each dot represents a set of 100 millions flips. The pattern seems similar to the previous figures, but again pay close attention the horizontal access which covers a smaller range of values. Now 96 of the 100 proportions are between 0.4999 and 0.5001. (In 100 million flips, The probability of heads on between 49.99\% and 50.01\% of flips is 0.977, so 96 out of 100 sets provides a rough estimate of this probability.) \begin{figure} \includegraphics[width=8.6in]{_graphics/coin-sim3} \caption{Proportion of flips which are heads in 100 sets of \textbf{100,000,000} fair coin flips. Each dot represents a set of \textbf{100,000,000} fair coin flips.}\label{fig:coin-sim3} \end{figure} The previous figures illustrate that the more flips there are, the more likely it is that we observe a proportion of flips landing on heads close to 0.5. We also see that with more flips we can refine our definition of ``close to 0.5'': increasing the number of flips by a factor of 100 (10,000 to 1,000,000 to 100,000,000) seems to give us an additional decimal place of precision (\(0.5\pm0.01\) to \(0.5\pm 0.001\) to \(0.5\pm 0.0001\).) These observations illustrate the relative frequency interpretation of probability. \begin{itemize} \tightlist \item The probability of an event corresponding to the result of a random phenomenon can be interpreted as the proportion of times that the event would occur in a very large number of hypothetical repetitions of the random phenomenon. \item That is, a probability can be interpreted as a \textbf{long run proportion} or \textbf{long run relative frequency}. \item This means that the probability of an event can be approximated by \textbf{simulating} the random phenomenon a large number of times and determining the proportion of simulated repetitions on which the event occurred out of the total number of repetitions of the simulation (this proportion is also called the relative frequency of the event.) \begin{itemize} \tightlist \item A \textbf{simulation} involves an artificial recreation of the random phenomenon, usually using a computer. \item For example, if a basketball player is successful on 90\% of her free throw attempts, we can simulate the player shooting a single free throw attempt by taking 10 cards and labeling 9 as ``success'' and 1 as ``miss'' then shuffling well and dealing one card. \end{itemize} \item The \textbf{long run relative frequency} interpretation of probability can be applied when a situation can be repeated numerous times, at least conceptually, and the outcome can be observed each time. \item The relative frequency of a particular event will settle down to a single constant value after many repetitions, and that long run value is the probability of that event. \begin{itemize} \tightlist \item However, what constitutes the random phenomenon or how the simulation is conducted depends on certain assumptions. Changing those assumptions can affect probabilities of interest. \begin{itemize} \tightlist \item For example, if you're interested in the probability that a die lands on 1, you need to know if it's a four-sided die or a six-sided die, and if the die is consider ``fair''. \item As a more complicated example, simulating the outcome of the next Superbowl involves many assumptions \end{itemize} \end{itemize} \end{itemize} \hypertarget{subjective-probability}{% \subsection{Subjective probability}\label{subjective-probability}} The relative frequency interpretation is natural in scenarios 1 through 8 of Exercise \ref{exr:randomness}. We can consider as repeateable situations like flipping a coin, drawing powerballs from a bin, or selecting a student at random. On the other hand, it is difficult to conceptualize scenarios 8 through 13 of Exercise \ref{exr:randomness} as relative frequencies. Superbowl 2020 will only be played once, the 2020 U.S. Presidential Election will only be conducted once (we hope), and there was only one April 17, 2009 on which you either did or did not eat an apple. But while these situations are not naturally repeatable they still involve randomness (uncertainty) and it is still reasonable to assign probabilities. At this point in time, the Chargers are less likely than the Patriots (ugh) to win Superbowl 2020, Donald Trump is more likely than Dwayne Johnson to win the U.S. 2020 Presidential Election, and if you've always been an ``apple-a-day'' person, there's a good chance you ate one on April 17, 2009. So it still makes sense to talk about probability in uncertain, but not necessarily repeated situations. However, the \emph{meaning} of probability does seem different in scenarios 9 through 13 compared to 1 through 8. Consider Superbowl 2020. As of Sept 16, \begin{itemize} \tightlist \item According to \href{https://projects.fivethirtyeight.com/2019-nfl-predictions/}{fivethirtyeight.com}, the Patriots have a 19\% chance of winning the Superbowl, the highest of any team, while the Chargers have a 4\% chance. \item According to \href{https://www.footballoutsiders.com/stats/playoffodds}{footballoutsider.com}, the Patriots have a 26\% chance of winning the Superbowl, the highest of any team, while the Chargers have a 6\% chance. \item According to \href{http://www.playoffstatus.com/nfl/nflpostseasonprob.html}{playoffstatus.com} the Patriots have a 7\% chance of winning the Superbowl, behind the Chiefs and Packers at 9\% each, while the Chargers have a 3\% chance. \end{itemize} All three websites, as well as many others, ascribe different probabilities to the Patriots or Chargers winning. Which website, if any, is correct? In the coin flipping example, we could perform a simulation to see that the long run relative frequency is 0.5. However, simulating Superbowl 2020 involves first simulating the 2019 season to determine the playoff matchups, then simulating the playoffs to see which teams make the Superbowl, then simulating the Superbowl matchup itself. And simulating the 2019 involves simulating all the weekly matchups and potential injuries and their effects. Even just simulating a single game involves many assumptions; differences in opinions with regards to these assumptions can lead to different probabilities. For example, according to fivethirtyeight, the Chiefs have a 69\% chance of beating the Ravens on Sept 22, but according to pickingpros.com it's only 52\%. Unlike in the coin flipping problem, there is no single set of rules for running the simulation, and there is no single relative frequency that determines the probability. Therefore, in a situation like forecasting the Superbowl we consider \emph{subjective probability}. \begin{itemize} \tightlist \item There are many situations where the outcome is uncertain, but it does mnot make sense to consider the situation as repeatable. In such situations, a \textbf{subjective (a.k.a. personal) probability} describes the degree of likelihood a given individual ascribes to a certain event. \item As the name suggests, different individuals might have different subjective (personal) probabilities for the same event. \begin{itemize} \tightlist \item In contrast to the long run relative frequency situation, in which the probability is agreed to be defined as the long run relative frequency. \end{itemize} \item The \href{https://fivethirtyeight.com/methodology/how-our-nfl-predictions-work/}{fivethirtyeight NFL predictions} are the output of a probabilistic forecast. \begin{itemize} \tightlist \item \textbf{Probabilistic forecasts} combine observed data and statistical models to make predictions. \item Rather than providing a single prediction (such as ``the Patriots will win Superbowl 2020''), probabilistic forecasts provide a range of scenarios and their relative likelihoods. \item Be sure to make a distinction between \emph{assumption} and \emph{observation}. \end{itemize} \end{itemize} \hypertarget{proportional-reasoning-and-tables-of-counts}{% \section{Proportional reasoning and tables of counts}\label{proportional-reasoning-and-tables-of-counts}} \begin{itemize} \tightlist \item In general, knowing probabilities of individual events alone is not enough to determine probabilities of combinations of them. \item \textbf{Two-way tables} (a.k.a. contingency tables) of counts are a useful tool for probability problems dealing with two events. \item For the purposes of constructing the table and computing related probabilities, any value can be used for the hypothetical total count (as long as you don't round numbers in between). \end{itemize} Suppose we are interested in the relationship between income and college graduation rates at Cal Poly. Consider the sample space \(S = \{\text{all current Cal Poly students}\}\). Suppose that the probability\footnote{These number are estimates based on data from \url{https://projects.propublica.org/colleges/schools/california-polytechnic-state-university-san-luis-obispo}} that a (randomly selected) Cal Poly student graduates within six years is 0.75, and that the probability that a (randomly selected) Cal Poly student has a Pell grant (for low income students) is 0.2. \begin{enumerate} \def\labelenumi{\arabic{enumi}.} \tightlist \item Do we have enough information to find the probability that a Cal Poly student both has a Pell Grant and graduates within six years? \item Without knowing any other information, what is the \emph{largest} value the probability in (a) could possibly be? Under what conditions is this value attained? Set up a two-way table corresponding to this scenario. \item Without knowing any other information, what is the \emph{smallest} value the probability in (a) could possibly be? Under what conditions is this value attained? Set up a two-way table corresponding to this scenario. \item Suppose that the probability that a Cal Poly student both has a Pell Grant and graduates within six years is 0.11. Construct the corresponding two-way table. \item Find the probability that a Cal Poly student does not have a Pell Grant and graduates within six years. \item Donny says ``75\% of CP students graduate within six years while 20\% of CP students have a Pell Grant. So 95\% of Cal Poly students graduate within six years or have a Pell Grant.'' Do you agree? \item What would need to be true in order for the Donny's statement in the previous part to be true? \end{enumerate} \hypertarget{consistency}{% \section{Working with probabilities}\label{consistency}} In the previous section we saw two different interpretations of probability: relative frequency and subjective. Fortunately, the mathematics of probability work the same way regardless of the interpretation. Also, even with subjective probabilities it is helpful to consider what might happen in a simulation. \hypertarget{consistency-requirements}{% \subsection{Consistency requirements}\label{consistency-requirements}} With either the relative frequency or personal probability interpretation there are some basic logical consistency requirements\footnote{In Section \ref{probspace}, we will formalize these requirements in the axioms of probability.} which probabilities need to satisfy. \begin{example} \protect\hypertarget{exm:worldseries}{}{\label{exm:worldseries} } As of Sept 18, the website \href{https://projects.fivethirtyeight.com/2019mlb-predictions/}{fivethirtyeight.com} listed the following probabilities for who will win the 2019 World Series. \end{example} \begin{longtable}[]{@{}lr@{}} \toprule \endhead Houston Astros & 25\%\tabularnewline Los Angeles Dodgers & 21\%\tabularnewline ew York Yankees & 20\%\tabularnewline tlanta Braves & 8\%\tabularnewline \bottomrule \end{longtable} \begin{enumerate} \def\labelenumi{\arabic{enumi}.} \tightlist \item Is the relative frequency or subjective probability interpretation more appropriate here? \item According to the site, what must be the probability that the Houston Astros do \emph{not} win? \item According to this site, what must be the probability that one of the above four teams is the World Series champion? \item According to this site, what must be the probability that a team other than the above four teams is the World Series champion? \end{enumerate} \begin{solution} \iffalse{} {Solution. } \fi{} to Example \ref{exm:worldseries} \end{solution} \begin{enumerate} \def\labelenumi{\arabic{enumi}.} \tightlist \item It is more appropriate to think of the probabilities themselves in application as subjective. Different websites or models could reasonably assign other probabilities to the teams. However, we can still imagine the probabilities as relative frequencies, if it helps our intuition. If we think of this as a simulation, each repetition results in a World Series champion and in the long run the Astros would be the champion in 25\% of repetitions. \item Either the Astros win or they don't; if there's a 25\% chance that the Astros win, there must be a 75\% chance that they do not win. If we think of this as a simulation, each repetition results in either the Astros winning or not, so if they win in 25\% of repetitions, they must not win in the other 75\% to account for 100\% of the repetitions. \item There is only one World Series champion, so if say the Astros win then no other team can win. Thinking again of a simulation, the repetitions in which the Astros win are distinct from those in which the Dodgers win. So if the Astros win in 25\% of repetitions and the Dodgers wins in 21\% repetitions, then on a total of 46\% of repetitions either the Astros or Dodgers win. Adding the four probabilities, we see that the probability that one of the four teams above wins must be 74\%. \item Either one of the four teams above wins, or some other team wins. If there is a 74\% chance that the winner is one of the four teams above, then there must be a 26\% chance that the winner is not one of these four teams. \end{enumerate} \hypertarget{odds}{% \subsection{Odds}\label{odds}} The words ``probability'', ``chance'', ``likelihood'', and ``odds'' are colloquially treated as synonyms. However, in the mathematical language of probability, \emph{odds} provide a different way of reporting a probability. Rather than reporting probability on a 0\% to 100\% scale, odds report probabilities in terms of ratios. \begin{example} \protect\hypertarget{exm:worldseries-odds}{}{\label{exm:worldseries-odds} } In Example \ref{exm:worldseries} the odds that the Astros win the World Series are 3 to 1 against. \end{example} \begin{enumerate} \def\labelenumi{\arabic{enumi}.} \tightlist \item What do you think that ``3 to 1 against'' means? \item What are the odds of the Astros \emph{not} winning? \item What are the odds of the Yankees winning? \item What are the odds of the Braves winning? \end{enumerate} \begin{solution} \iffalse{} {Solution. } \fi{} to Example \ref{exm:worldseries-odds} \end{solution} \begin{enumerate} \def\labelenumi{\arabic{enumi}.} \tightlist \item The probability that the Astros win is 0.25, so the probability that they do not win is 0.75. These numbers are in a 3 to 1 ratio: the probability of not winning (0.75) is 3 times greater than the probability of winning (0.25). So the odds \emph{against} the Astros winning the World Series are 3 to 1; ``against'' because the Astros are less likely to win than to not win. \item The probabilities are still in the 3 to 1 ratio, but we can say that the odds are 3 to 1 \emph{in favor} of the Astros \emph{not} winning. \item The probability that the Yankees win is 0.2 and that they don't win is 0.8, and \(0.8/0.2 = 4\)). So the odds are 4 to 1 against the Yankees winning (``against'' because the Yankees are less likely to win than to not win). \item The probability that the Braves win is 0.08 and that they don't win is 0.92, and \(0.92/0.08 = 11.5\)). So the odds are 11.5 to 1, or 23 to 2, against the Braves winning (``against'' because the Braves are less likely to win than to not win). \end{enumerate} \begin{itemize} \tightlist \item The \textbf{odds} of an event is a ratio involving the probability that the event occurs and the probability that the event does not occur \[ \begin{aligned} \text{odds in favor} & = \frac{\text{probability that the event occurs}}{\text{probability that the event does not occur}} \\ & \\ \text{odds against} & = \frac{\text{probability that the event does not occur}}{\text{probability that the event occurs}}\end{aligned} \] \item In many situations (e.g., gambling) odds are implicitly reported as odds against. \item Odds are usually expressed as whole numbers, e.g., 11 to 1, 7 to 2. \end{itemize} Ron and Leslie make the following bet. If Boston wins, Leslie will pay Ron \$200; if not, Ron will pay Leslie \$100. If both consider this to be a fair bet, what have they agreed that the probability that Boston wins is? The odds of a fair bet on whether or not an event will occur imply a probability for the event \[\text{probability that event occurs} = \frac{\text{odds in favor of the event}}{1+\text{odds in favor of the event}}\] \hypertarget{dutch-book}{% \subsection{Dutch book}\label{dutch-book}} Dutch book\footnote{``Book'' in the sense of a bookie taking bets} Odds give us one way to see why even subjective probabilities most follow basic logical consistency requirements. \begin{example} \protect\hypertarget{exm:dutch}{}{\label{exm:dutch} } Donny Dont is pretty sure that the Astros are going to win the World Series. He thinks their only real competition is the Braves. The following are Donny's subjective probabilities. \begin{longtable}[]{@{}lr@{}} \toprule \endhead Houston Astros & 60\%\tabularnewline Atlanta Braves & 20\%\tabularnewline Other & 10\%\tabularnewline \bottomrule \end{longtable} \end{example} \hypertarget{sim}{% \section{Approximating probabilities - a brief introduction to simulation}\label{sim}} Here's a seemingly simple problem. Flip a fair coin four times and record the results in order. For the recorded sequence, compute \emph{the proportion of the flips which immediately follow a H that result in H}. What value do you expect for this proportion? (If there are no flips which immediately follow a H, i.e.~the outcome is either TTTT or TTTH, discard the sequence and try again with four more flips.) For example, the sequence HHTT means the the first and second flips are heads and the third and fourth flips are tails. For this sequence there are two flips which immediately followed heads, the second and the third, of which one (the second) was heads. So the proportion in question for this sequence is 1/2. So what value do you expect for this proportion? We think it's safe to say that most people would answer 1/2. Afterall, it shouldn't matter if a flip follows heads or not, right? We would expect half of the flips to land on heads regardless of whether the flip follows H, right? We'll see there are some subtleties lurking behind these questions. To get an idea of what we would expect for this proportion, we could conduct a simulation: flip a coin 4 times and see what happens. Here are the results of a few repetitions; each repetition consists of an ordered sequence of 4 coin flips for which the proportion in question is measured. (\textbf{Flips which immediately follow H are in bold.}) \begin{longtable}[]{@{}rrllr@{}} \caption{\label{tab:mscoin-intro} Simulated outcomes for 6 sets of four flips of a fair coin.}\tabularnewline \toprule \begin{minipage}[b]{0.12\columnwidth}\raggedleft Repetition \textbar{}\strut \end{minipage} & \begin{minipage}[b]{0.10\columnwidth}\raggedleft Outcome \textbar{} Fl\strut \end{minipage} & \begin{minipage}[b]{0.20\columnwidth}\raggedright Flips that follow H \textbar{}\strut \end{minipage} & \begin{minipage}[b]{0.16\columnwidth}\raggedright H that follow H \textbar{} Pro\strut \end{minipage} & \begin{minipage}[b]{0.28\columnwidth}\raggedleft Proportion of H following H \textbar{}\strut \end{minipage}\tabularnewline \midrule \endfirsthead \toprule \begin{minipage}[b]{0.12\columnwidth}\raggedleft Repetition \textbar{}\strut \end{minipage} & \begin{minipage}[b]{0.10\columnwidth}\raggedleft Outcome \textbar{} Fl\strut \end{minipage} & \begin{minipage}[b]{0.20\columnwidth}\raggedright Flips that follow H \textbar{}\strut \end{minipage} & \begin{minipage}[b]{0.16\columnwidth}\raggedright H that follow H \textbar{} Pro\strut \end{minipage} & \begin{minipage}[b]{0.28\columnwidth}\raggedleft Proportion of H following H \textbar{}\strut \end{minipage}\tabularnewline \midrule \endhead \begin{minipage}[t]{0.12\columnwidth}\raggedleft 1 \textbar{}\strut \end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedleft H\textbf{HT}T \textbar{}\strut \end{minipage} & \begin{minipage}[t]{0.20\columnwidth}\raggedright 2 \textbar{}\strut \end{minipage} & \begin{minipage}[t]{0.16\columnwidth}\raggedright 1 \textbar{}\strut \end{minipage} & \begin{minipage}[t]{0.28\columnwidth}\raggedleft 0.5 \textbar{}\strut \end{minipage}\tabularnewline \begin{minipage}[t]{0.12\columnwidth}\raggedleft 2 \textbar{}\strut \end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedleft H\textbf{T}TH \textbar{}\strut \end{minipage} & \begin{minipage}[t]{0.20\columnwidth}\raggedright 1 \textbar{}\strut \end{minipage} & \begin{minipage}[t]{0.16\columnwidth}\raggedright 0 \textbar{}\strut \end{minipage} & \begin{minipage}[t]{0.28\columnwidth}\raggedleft 0 \textbar{}\strut \end{minipage}\tabularnewline \begin{minipage}[t]{0.12\columnwidth}\raggedleft 3 \textbar{}\strut \end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedleft TTTH \textbar{}\strut \end{minipage} & \begin{minipage}[t]{0.20\columnwidth}\raggedright 0 \textbar{}\strut \end{minipage} & \begin{minipage}[t]{0.16\columnwidth}\raggedright NA \textbar{}\strut \end{minipage} & \begin{minipage}[t]{0.28\columnwidth}\raggedleft try again \textbar{}\strut \end{minipage}\tabularnewline \begin{minipage}[t]{0.12\columnwidth}\raggedleft 4 \textbar{}\strut \end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedleft TH\textbf{HH} \textbar{}\strut \end{minipage} & \begin{minipage}[t]{0.20\columnwidth}\raggedright 2 \textbar{}\strut \end{minipage} & \begin{minipage}[t]{0.16\columnwidth}\raggedright 2 \textbar{}\strut \end{minipage} & \begin{minipage}[t]{0.28\columnwidth}\raggedleft 1 \textbar{}\strut \end{minipage}\tabularnewline \begin{minipage}[t]{0.12\columnwidth}\raggedleft 5 \textbar{}\strut \end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedleft H\textbf{HT}T \textbar{}\strut \end{minipage} & \begin{minipage}[t]{0.20\columnwidth}\raggedright 2 \textbar{}\strut \end{minipage} & \begin{minipage}[t]{0.16\columnwidth}\raggedright 1 \textbar{}\strut \end{minipage} & \begin{minipage}[t]{0.28\columnwidth}\raggedleft 0.5 \textbar{}\strut \end{minipage}\tabularnewline \begin{minipage}[t]{0.12\columnwidth}\raggedleft 6 \textbar{}\strut \end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedleft H\textbf{HHT} \textbar{}\strut \end{minipage} & \begin{minipage}[t]{0.20\columnwidth}\raggedright 3 \textbar{}\strut \end{minipage} & \begin{minipage}[t]{0.16\columnwidth}\raggedright 2 \textbar{}\strut \end{minipage} & \begin{minipage}[t]{0.28\columnwidth}\raggedleft 0.667 \textbar{}\strut \end{minipage}\tabularnewline \bottomrule \end{longtable} We can keep repeating the above process to investigate what happens in the long run. Rather than actually flipping coins, we use a computer to run a simulation. The table and plot below summarize the results of 1,000,000 repetitions of the simulation\footnote{Section XXX covers how to program the simulation and analyze the results.}. While you can't see the individual ``dots'' in the plot, each dot would represent a sequence of 4 coin flips (with at least one flip following a H) and the value plotted being plotted is the proportion of H following H for that sequence. The results could be summarized in a table like Table \ref{tab:mscoin-intro}, albeit with 1,000,000 rows (after discarding rows with no flips immediately following H.) \begin{figure} \includegraphics[width=0.5\linewidth]{_graphics/mscoin-intro-table} \includegraphics[width=0.5\linewidth]{_graphics/mscoin-intro-plot} \caption{Proportion of flips immediately following Heads that result in Heads for 1,000,000 sets of 4 coin flips. (Each set has at least one flip immediately following H.) For example, the proportion in 429,123 of sets}\label{fig:ms-coin-intro-plot} \end{figure} We asked the question: \emph{what would you expect} for the proportion of the flips which immediately follow a H that result in H? That depends on how we define what's ``expected''. If we are interested in the value that is most likely to occur when we flip a coin four times, then the answer is 0: we see that in the long run a little over 40\% of the sets resulted in a proportion of 0, while only about 30\% of sets resulted in a value of 1/2. We see that the plot is not centered at 1/2; a higher percentage of repetitions resulted in a proportion below 1/2 than above 1/2. We think that most people would find this surprising. Another way to interpret ``expected'' is as ``average''. Just as probability can be interpreted as long run relative frequency, there is a concept called \emph{expected value} which can be interpreted as the \emph{long run average value}. After 1,000,000 repetitions, each involving a set of four fair coin flips, we have 1,000,000 simulated values of the proportion of H following H, as recorded in the rightmost column of Table \ref{tab:mscoin-intro}. We could then average these values: add up the values in the column and divide by 1,000,000. It turns out that average value is 0.405, which is not 1/2. Again, we think most people find this surprising. A quick note: the term ``expected value'' is somewhat of a misnomer. We are \emph{not} saying that if we flip a coin four times we would expect the proportion of H following H for that set of flips to be 0.405. In fact, the simulation shows that on any single set of four fair coin flips, the only possible values for the proportion of H following H are 0, 1/2, 2/3, and 1. So in a set of four coin flips it's not possible to see a proportion of 0.405. Rather, 0.405 is the \emph{average value of the proportion of H following H that we would expect to see in the long run over many sets of four fair coin flips}. We will return to this idea later. We will return to this example several times throughout the book to investigate these results more closely. For now, just observe that \begin{itemize} \tightlist \item The study of probability can involve some subtleties and our intuition isn't always right. \item Simulation is an effective way of investigating probability problems, and can reveal interesting and suprising patterns. \end{itemize} In MS coin - add statement about probability of H after H versus proportion of H after H \hypertarget{sliding-scale-of-probability-or-probability-of-what}{% \section{Sliding scale of probability, or Probability of what?}\label{sliding-scale-of-probability-or-probability-of-what}} \href{https://mathwithbaddrawings.com/2015/09/23/what-does-probability-mean-in-your-profession/}{Here's a funny series of cartoons} What does 1/million mean? At least one, etc. xkcd/538 benchmarks, put in benchmarks (one in a million, a billion, etc) probability of coincidences \hypertarget{common-misinterpretation-and-fallacies-e.g.-outbreak-of-asian-disease-utts-book}{% \section{Common misinterpretation and fallacies (e.g.~outbreak of Asian disease, Utts book)}\label{common-misinterpretation-and-fallacies-e.g.-outbreak-of-asian-disease-utts-book}} Sally Clark? Allais paradox? A famous study\footnote{Source: \url{https://www.ncbi.nlm.nih.gov/pubmed/7455683}} by Kahneman and Tversky presented a group of people with the following scenario.\\ ~\\ "Imagine that the U.S. is preparing for the outbreak of an unusual Asian disease, which is expected to kill 600 people. Two alternative programs to combat the disease have been proposed. Assume that the exact scientific estimate of the consequences of the programs are as follows: If Program A is adopted, 200 people will be saved. If Program B is adopted, there is 1/3 probability that 600 people will be saved, and 2/3 probability that no people will be saved. Which of the two programs would you favor?"\\ Which of these two options, A or B, would you choose? Of the 152 participants, a large majority (72\%) favored one of the options; which one do you think it was? A second group was presented with the same set up, but the following options instead of A/B.\\ If Program C is adopted 400 people will die. If Program D is adopted there is 1/3 probability that nobody will die, and 2/3 probability that 600 people will die.\\ Which of these two options, C or D, would you choose? Of the 155 participants, a large majority (78\%) favored one of the options; which one do you think it was? Compute the expected number of people who die and who are saved with Program D. Compute the expected number of people who die and who are saved with Program B. Compare options A and C. Are these the same? How about B and D? Do the risk preferences depend on the wording of how the information is presented? Many studies have shown that human intuition does not generally deal well with issues of uncertainty. So it's worthwhile to take a careful study \begin{example}[Monty Hall problem] \protect\hypertarget{exm:monty-hall}{}{\label{exm:monty-hall} \iffalse (Monty Hall problem) \fi{} }MOnty Hall in CHpater 1??? \end{example} \hypertarget{why-study-coins-dice-cards-and-spinners}{% \section{Why study coins, dice, cards, and spinners?}\label{why-study-coins-dice-cards-and-spinners}} Many probability problems involve ``toy'' situations like flipping coins, rolling dice, shuffling cards, or spinning spinners. These situations might seem unexciting, or at least not very practically meaningful. However, coins and spinners and the like provide familiar, concrete situations which facilitate understanding of probability concepts. Furthermore, simple situations often provide insight into real and complex problems. The following is just one illustration. Many basketball players and fans alike believe in the ``hot hand'' phenomenon: the idea that making several shots in a row increases a player's chances of making the next shot. However, the consensus conclusion of thirty years of studies on the hot hand, beginning with the seminal study \citet{GVT}, had been that there is no statistical evidence that the hot hand in basketball is real. As a result, many statisticians regularly caution against the ``hot hand fallacy'': the belief that the hot hand exists when, in reality, the degree of streaky behavior typically observed in sequential data is consistent with what would be expected simply by chance in independent trials. The idea behind studies like \citet{GVT} is essentially the following. Consider a player who attempts 100 shots and makes 50\%. If there is no hot hand, then we might expect the player to make 50\% of shots both on attempts that follow hit streaks --- usually considered three (or more) made attempts in a row --- and on other attempts. Therefore, a success rate of 50\% on both sets of attempts provides no evidence of the hot hand. However, recent research of \citet{MStruth}, \citet{MSthree}, \citet{MScold} concludes that previous studies on the hot hand in basketball, starting with \citet{GVT}, have been subject to a bias. After correcting for the bias, the authors find strong evidence in favor of the hot hand effect in basketball shooting, suggesting the hot hand fallacy is not a fallacy after all. One interesting aspect of these studies is that Miller and Sanjurjo's methods are simulation-based. \citet{MStruth} introduced the coin flipping problem in Section \ref{sim} to illustrate the idea behind their research and the bias in previous studies. Consider again a player who attempts 100 shots and makes 50\%. Even if there is no hot hand, Miller and Sanjurjo show that we would actually expect the player to have a shooting percentage of \emph{strictly less than} 50\% on the attempts which followed streaks, and strictly greater than 50\% on the other attempts. The reason is the same as for the coin flipping problem in Section \ref{sim}: in a fixed number of trials, the proportion of H on trials following H is expected to be less than the true probability of H, even though the trials are independent. Therefore, for the example player a success rate of 50\% on both sets of attempts actually provides directional evidence in favor of the hot hand. Properly acccounting for this bias leads to substantially different statistical analyses (i.e., p-values) and conclusions. \hypertarget{probmath}{% \chapter{The Language of Probability}\label{probmath}} CHANGE EVAL TO TRUE AFTER FIGURE PYTHON ERRORS OUT This chapter introduces the fundamental terminology, objects, and mathematics of random phenomena. \hypertarget{samplespace}{% \section{Sample space of outcomes}\label{samplespace}} A phenomenon is \textbf{random} if there are multiple potential \emph{outcomes}, and there is \emph{uncertainty} about which outcome will occur. Because there is wide variety in types of random phenomna, an outcome can be virtually anything: \begin{itemize} \tightlist \item a sequence of coin flips \item a shuffle of a deck of cards \item the weather tomorrow in your city \item the path of a hurricane \item a sample of registered voters \item player locations over time in an NBA game (as recorded by the \href{https://www.stats.com/sportvu-basketball/}{SportsVU system}) \end{itemize} And on and on. In particular, an outcome does \emph{not} have to be a number. The first step in defining a model for a random phenomenon is to describe the possible outcomes. \begin{definition} \protect\hypertarget{def:sample-space}{}{\label{def:sample-space} } The \textbf{sample space}, denoted \(\Omega\) (the uppercase Greek letter ``omega''), is the set of all possible outcomes of a random phenomenon. An \textbf{outcome}, denoted \(\omega\) (the lowercase Greek letter ``omega''), is an element of the sample space: \(\omega\in\Omega\). \end{definition} Mathematically, the sample space \(\Omega\) is a \emph{set} containing all possible outcomes, while an indvidual outcome \(\omega\) is a \emph{point} or \emph{element} in \(\Omega\). The symbol \(\omega\) denotes a generic outcome, much like the symbol \(u\) in \(\sqrt{u}\) denotes a generic input to the square root function. For example, the simplest random phenomena have just two distinct outcomes, in which case the sample space is just a set with two elements, e.g.~\(\Omega=\{\text{no}, \text{yes}\}\), \(\Omega=\{\text{off}, \text{on}\}\), \(\Omega=\{0, 1\}\), \(\Omega=\{-1, 1\}\). For example, the sample space for a single coin flip could be \(\Omega = \{H, T\}\). If the coin lands on heads, we observe the outcome \(\omega = H\); if tails we observe \(\omega=T\). A random phenomenon is modeled by a \emph{single} sample space, upon which all objects are defined. These objects, which we will encounter later, include events, random variables, stochastic processes. Whenever possible, a sample space outcome should be defined to provide the maximum amount of information about the outcome of random phenomenon. While a random phenomenon always has a corresponding sample space, we will see that in many situations the sample space of outcomes is at best only vaguely specified and can not be feasibly enumerated. \begin{example} \protect\hypertarget{exm:dice-outcome}{}{\label{exm:dice-outcome} } Roll a four-sided die\footnote{Why four-sided? Simply to make the number of possibilities a little more manageable (e.g., for in-class simulation activities). Rolling a four-sided die twice yields 16 possible pairs, while rolling a six-sided die yields 36 possible pairs.} twice, and record the result of each roll in sequence as an ordered pair. For example, the outcome \((3, 1)\) represents a 3 on the first roll and a 1 on the second; this is not the same outcome as \((1, 3)\). \end{example} \begin{enumerate} \def\labelenumi{\arabic{enumi}.} \tightlist \item Identify the sample space. \item We might be interested in the sum of the two dice. Explain why it is still advantageous to define the sample space as in the previous part, rather than as \(\Omega=\{2, \ldots, 8\}\). \end{enumerate} \begin{solution} \iffalse{} {Solution. } \fi{}to Example \ref{exm:dice-event} \end{solution} \begin{enumerate} \def\labelenumi{\arabic{enumi}.} \tightlist \item The sample space consists of 16 possible ordered pairs of rolls \end{enumerate} \begin{align*} \Omega & = \{(1, 1), (1, 2), (1, 3), (1, 4),\\ & \qquad (2, 1), (2, 2), (2, 3), (2, 4),\\ & \qquad (3, 1), (3, 2), (3, 3), (3, 4),\\ & \qquad (4, 1), (4, 2), (4, 3), (4, 4)\} \end{align*} It is more helpful to represent the above set in a table like the following \begin{enumerate} \def\labelenumi{\arabic{enumi}.} \tightlist \item Yes, we might be interested in the sum of the two dice. But we might also be interested in other things, like the larger of the two rolls, or if at least one 3 was rolled, or the first number rolled. Knowing just the sum of the dice does not provide as much information about the outcome of the random phenomenon as the sequence of individual rolls does. \end{enumerate} \textbf{Note:} In the previous example, there was a single sample space whose outcomes represented the result of the pair of rolls. In particular, there was not a separate sample space for each of the individual rolls. Now, we could have written the sample space as the Cartesian product \(\Omega = \{1, 2, 3, 4\} \times\{1, 2, 3, 4\}\), where the first, respectively second, set the in the product represents the result of the first, respectively second, roll. But this Cartesian product represents a single set of ordered pairs, and it is that single set which is the sample space corresponding to outcomes of the pair of rolls. \begin{example} \protect\hypertarget{exm:coin-outcome}{}{\label{exm:coin-outcome} } Consider the outcome of a sequence of 4 flips of a coin. \end{example} \begin{enumerate} \def\labelenumi{\arabic{enumi}.} \tightlist \item Identify an appropriate sample space. \item We might be interested in the number of heads flipped. Explain why it is still advantageous to define the sample space as in the previous part, rather than as \(\Omega=\{0, 1, 2, 3, 4\}\). \end{enumerate} \begin{solution} \iffalse{} {Solution. } \fi{}to Example \ref{exm:coin-outcome} \end{solution} \begin{enumerate} \def\labelenumi{\arabic{enumi}.} \tightlist \item An outcome is an ordered sequence representing the results of the four flips. For example, HTHT means heads on the first on third flips and tails on the second and fourth; this is not the same outcome as HHTT or THTH. The sample space is the following set composed of 16 distinct outcomes \begin{align*} \Omega & = \{HHHH, HHHT, HHTH, HTHH, THHH, HHTT, HTHT, HTTH,\\ & \qquad THHT, THTH, TTHH, HTTT, THTT, TTHT, TTTH, TTTT\} \end{align*} \item Yes, we might be interested in the number of heads flipped, but we might also be interested in other things, such as whether the first flip was heads, the length of the longest streak of heads in a row, or the proportion of flips following H that resulted in H. Knowing just the number of heads flipped does not provide as much information about the outcome of the random phenomenon as the sequence of individual flips does. \end{enumerate} \textbf{Note:} We reiterate what we said after Example \ref{exm:dice-event}. In the previous example, there was a single sample space whose outcomes were sequences of coin flips. In particular, there was not a separate sample space for each of the individual flips. We could have written the sample space as the Cartesian product \(\Omega = \{H, T\}\times \{H, T\}\times \{H, T\}\times \{H, T\} = \{H, T\}^4\). But this Cartesian product represents a single set of sequences of 4 flips, and it is this single set which is the sample space corresponding to the sequence of four flips. \begin{example}[Matching problem] \protect\hypertarget{exm:matching-outcome}{}{\label{exm:matching-outcome} \iffalse (Matching problem) \fi{} } The ``matching problem'' is one well known probability problem. The following version is from \href{https://fivethirtyeight.com/features/everythings-mixed-up-can-you-sort-it-all-out/}{FiveThirtyEight}. A geology museum in California has four different rocks sitting in a row on a shelf, with labels on the shelf telling what type of rock each is. An earthquake hits and the rocks all fall off the shelf and get mixed up. A janitor comes in and, wanting to clean the floor, puts the rocks back on the shelf in random order. We might be interested in whether all the rocks are put back in the correct spot, or none are, or if the heaviest rock is put back in the correct spot. Label the rocks 1, 2, 3, 4, and also label the spots 1, 2, 3, 4. Identify an appropriate sample space. \end{example} \begin{solution} \iffalse{} {Solution. } \fi{}to Example \ref{exm:matching-outcome} \end{solution} We can consider each outcome to be a particular placement of rocks in the spots. For example, the outcome 3214 (or \((3, 2, 1, 4)\)) represents that rock 3 is placed in spot 1, rock 2 in spot 2, rock 1 in spot 3, and rock 4 in spot 4. (We say that an outcome is a \emph{permutation} (or reordering) of the numbers 1, 2, 3, 4.) So the sample space consists of the following 24 outcomes\footnote{There are 4 rocks that could potentially go in spot 1, then 3 rocks that could potentially go in spot 2, 2 to spot 3, and 1 left for spot 4. This results in \(4\times3\times2\times1=4! = 24\) possible outcomes. We will see more counting rules in XXXX.}. \begin{align*} \Omega & = \{1234, 1243, 1324, 1342, 1423, 1432 \\ & \qquad 2134, 2143, 2314, 2341, 2413, 2431 \\ & \qquad 3124, 3142, 3214, 3241, 3412, 3421 \\ & \qquad 4123, 4132, 4213, 4231, 4312, 4321\} \end{align*} Recording outcomes in this way provides more information than if we had chosen the sample space to correspond to, for example, the number of rocks that were placed in the correct spot. \begin{example}[Collector problem] \protect\hypertarget{exm:collector-outcome}{}{\label{exm:collector-outcome} \iffalse (Collector problem) \fi{} } So-called ``collector problems'' concern the following generic scenario. A set of \(n\) cards labeled \(1, 2, \ldots, n\) are placed in a box (or shuffled in a deck). Cards are selected one at a time, \emph{with replacement}, indefinitely. Identify an appropriate sample space. Selection with replacement means that a card which has been selected is returned to the box and the cards are reshuffled before the next draw is made. (``Collector problems'' typically concern the number of draws needed to observe each of the \(n\) tickets. For example, roll a fair six-sided die until each of the six faces is rolled at least once, or collecting prizes until a complete set is obtained.) \end{example} \begin{solution} \iffalse{} {Solution. } \fi{}to Example \ref{exm:collector-outcome} \end{solution} We can let \(\Omega=\{1, \ldots, n\}^\infty\). That is, each outcome is an infinite sequence --- since draws continue indefinitely --- with each element in the sequence in \(\{1, \ldots, n\}\). For example, \((3, 2, 6, 3, 4, 1, 2, 4, \ldots)\) means card 3 is the first selection, card 2 the second, card 6 the third, card 3 the fourth, etc. Recording outcomes in this way, we could investigate the number of draws needed to obtain each of the \(n\) cards at least \(r\) times, for any \(r=1,2, \ldots\). (Note that \(\Omega\) is an uncountable set.) \begin{example} \protect\hypertarget{exm:sampling-outcome}{}{\label{exm:sampling-outcome} }Many statistical applications involve \emph{random sampling}. For example, polling organizations often select random samples of Americans. Typically the selection involves random digit dialing: a sample of say 1000 phone numbers are randomly selected from some large bank (hundreds of millions) of phone numbers; this is the \emph{population}. An outcome would consist of the 1000 phone numbers selected; this is the \emph{sample}. As an extraordinarily unrealistic, oversimplified, but concrete example, suppose the bank only contains 5 numbers, labeled \{1, 2, 3, 4, 5\}, from which 3 are selected. Describe an appropriate sample space. Note: the order in which the numbers are selected does not matter; we only care which numbers are selected. \end{example} \begin{solution} \iffalse{} {Solution. } \fi{}to Example \ref{exm:sampling-outcome} \end{solution} An outcome consists of a \emph{subset} of size 3 from the set \(\{1, 2, 3, 4, 5\}\), representing the list of the 3 phone numbers selected. There are 10 distinct outcomes \[ \Omega = \{\{1, 2, 3\}, \{1, 2, 4\}, \{1, 2, 5\}, \{1, 3, 4\}, \{1, 3, 5\},\\ \qquad\quad \{1, 4, 5\}, \{2, 3, 4\},\{2, 3, 5\},\{2, 4, 5\},\{3, 4, 5\}\} \] In a more realistic setting, the population would consist of hundreds of millions of phone numbers, and the sample space would be composed of all possible subsets (samples) of 1000 phone numbers. Even if the order in which the numbers are selected is irrelevant, the sample space is enormous and could never be feasibly enumerated as in this oversimplified example. But the idea is the same: an outcome consists of a \emph{subset} of numbers, and the sample space is a collection of possible subsets. (That it, the sample space is a set of sets.) RANDOM ASSIGNMENT EXAMPLE, or save for exercise? \begin{example} \protect\hypertarget{exm:meeting-outcome}{}{\label{exm:meeting-outcome} } Regina and Cady plan to meet for lunch between noon and 1 but they are not sure of their arrival times. We might be interested in questions involving whether they arrive within 15 minutes of one another, who arrives first, or how long the first person to arrival needs to wait for the second, Describe an appropriate sample space. Rather than dealing with clock time, it is helpful to represent noon as time 0 and measure time as fraction of the hour after noon, so that times take values in the continuous interval {[}0, 1{]}. For example, 12:15 corresponds to a time of 0.25, 12:30 to 0.5, 12:42 to 0.7. \end{example} \begin{solution} \iffalse{} {Solution. } \fi{} to Example \ref{exm:meeting-outcome} \end{solution} An outcome is a pair of values \(\omega = (\omega_1, \omega_2)\) corresponding to the arrival times of (Regina, Cady). For example, the outcome (0.5, 0.7) represents Regina arriving at time 0.5 (12:30) and Cady at time 0.7 (12:42), while (0.7, 0) represents Regina arriving at time 0.7 (12:42) and Cady at time 0 (noon). The sample space is \(\Omega = [0,1]\times [0,1]=[0,1]^2\), the Cartesian product \(\{(\omega_1, \omega_2): \omega_1 \in [0, 1], \omega_2 \in [0, 1]\}\). In the above example, outcomes were measured on a continuous scale; any real number between 0 and 1 was a possible outcome of a single spin (of the idealized, infinitely precise spinner). Even in situations where outcomes are inherently discrete, it is often more convenient to model them as continuous. For example, if an outcome represents the annual salary in dollars of a randomly selected U.S. household, it would be more convenient to model the sample space as the continuous interval\^{}{[}We could also try \([0, m]\) where \(m\) is some large dollar amount providing an upper bound on the maximum possible salary. But we would need to be sure that \(m\) is large enough so that all possible outcomes are in the sample space \([0, m]\). Without knowing this bound in advance, it is convenient to just choose the unbounded interval \([0, \infty)\).{]} \([0, \infty)\) rather than \(\{0, 1, 2, \ldots\}\) or \(\{0, 0.01, 0.02, \ldots\}\). \begin{example} \protect\hypertarget{exm:uniform-outcome}{}{\label{exm:uniform-outcome} } Many games involve rolling a die or spinning a spinner like the one in Figure \ref{fig:uniform-spinner} which returns values between 0 and 1. A spinner can be thought of as a continuous analog of a die roll. The values in the picture are rounded to two decimal places, but consider an idealized model where the spinner is infinitely precise so that any real number between 0 and 1 is a possible outcome. The sample space corresponding to a single spin is then \(\Omega = [0, 1]\), a continuous interval of real numbers. Now suppose the spinner is spun twice; what is an appropriate sample space? \end{example} \begin{figure} \includegraphics[width=5.69in]{_graphics/uniform-spinner} \caption{A Uniform(0, 1) spinner. The values in the picture are rounded to two decimal places, but in the idealized model the spinner is infinitely precise so that any real number between 0 and 1 is a possible outcome.}\label{fig:uniform-spinner} \end{figure} \begin{solution} \iffalse{} {Solution. } \fi{} to Example \ref{exm:uniform-outcome} \end{solution} An outcome is now a pair of values \((\omega_1, \omega_2\)) corresponding to the results of the first and second spins. The sample space is \(\Omega = [0,1]\times [0,1]\), where \([0,1]\times [0,1]\), also denoted \([0,1]^2\), is the Cartesian product \([0,1]\times [0,1] = \{(\omega_1, \omega_2): \omega_1 \in [0, 1], \omega_2 \in [0, 1]\}\). In the above (idealized) example, outcomes were measured on a continuous scale; any real number between 0 and 1 was a possible outcome of a single spin (of the idealized, infinitely precise spinner). Even in situations where outcomes are inherently discrete, it is often more convenient to model them as continuous. For example, if an outcome represents the annual salary in dollars of a randomly selected U.S. household, it would be more convenient to model the sample space as the continuous interval\^{}{[}We could also try \([0, m]\) where \(m\) is some large dollar amount providing an upper bound on the maximum possible salary. But we would need to be sure that \(m\) is large enough so that all possible outcomes are in the sample space \([0, m]\). Without knowing this bound in advance, it is convenient to just choose the unbounded interval \([0, \infty)\).{]} \([0, \infty)\) rather than \(\{0, 1, 2, \ldots\}\) or \(\{0, 0.01, 0.02, \ldots\}\). \begin{example} \protect\hypertarget{exm:SAT-outcome}{}{\label{exm:SAT-outcome} }Select a U.S. high school student and record the student's SAT Math and Reading score. What is an appropriate sample space? \end{example} \begin{solution} \iffalse{} {Solution. } \fi{}to Example \ref{exm:SAT-outcome} \end{solution} An outcome will be an ordered pair represent (Math, Reading) score. Technically, possible scores are 200 through 800 in increments of 10. So we could consider the sample space to be \(\{200, 210, 220, \ldots, 790, 800\}\times \{200, 210, 220, \ldots, 790, 800\}\). However, we could also model scores on a continuous scale, taking any value in the interval from 200 to 800. In this case, the sample space would be \(\Omega = [200, 800] \times [200, 800]\). Such a specification is often more convenient mathematically. Add somewhere something like: In practice we rarely enumerate the sample space as we did in the examples in this section. Nonetheless, there is always some underlying sample space corresponding to all possible outcomes of the random phenomenon. Even when we do not specify the sample space, it is important to consider what the sample space is. We must first determine what is possible before determining when is probable. The sample space in essence defines our denominator. Does the sample space corresponding to a single lottery ticket or some lottery ticket somewhere? (Need an example that highlights different denominators of sample space. Maybe like Oscar winner example?) \hypertarget{events}{% \section{Events}\label{events}} In a random phenomenon, an ``event'' is something that could happen. For example, if we're interested in tomorrow's weather, events include \begin{itemize} \tightlist \item ``the high temperature is 75°F'' \item ``the high temperature is above 75°F'' \item ``it rains'' \item ``it does not rain'' \item ``it rains and the high temperature is above 75°F'' \item and so on \end{itemize} Mathematically, an \emph{event} is a collection of sample space outcomes that satisfy some criteria. \begin{definition} \protect\hypertarget{def:event}{}{\label{def:event} }An \textbf{event} \(A\) is a \emph{subset} of the sample space: \(A\subseteq \Omega\). The collection of all events of interest\footnote{For the purposes of this text, \(\mathcal{F}\) can be considered to be the set of all subsets of \(\Omega\). Technically, \(\mathcal{F}\) is a \emph{\(\sigma\)-field} of subsets of \(\Omega\): \(\mathcal{F}\) contains \(\Omega\) and is closed under countably many elementary set operations (complements, unions, intersections). This requirement ensures that if \(A\) and \(B\) are ``events of interest'', then so are \(A\cup B\), \(A\cap B\), and \(A^c\). While this level of technical detail is not needed, we prefer to introduce the idea of a ``collection of events'' now since a probability measure is a function whose input is an event (set) and not an outcome.} is denoted \(\mathcal{F}\). If the random phenomenon yields outcome \(\omega\), we say ``event \(A\) occurred'' if \(\omega\in A\). \end{definition} \begin{itemize} \tightlist \item Recall that the sample space is the collection of all possible outcomes of a random phenomenon. \item An event represents those outcomes which satisfy some criteria. \item There is a single sample space, upon which all events are defined. \item An outcome in a sample space should be defined to record as much information as possible so that the occurrence or non-occurrence of all events of interest can be determined. \item Events are typically denoted with capital letters near the start of the alphabet, with or without subscripts (e.g.~\(A\), \(B\), \(C\), \(A_1\), \(A_2\)) \item Events can be composed from others using \href{https://en.wikipedia.org/wiki/Set_(mathematics)\#Basic_operations}{basic set operations} like unions (\(A\cup B\)), intersections (\(A \cap B\)), and complements (\(A^c\)). \begin{itemize} \tightlist \item Read \(A^c\) as ``not'' \(A\). \item Read \(A\cap B\) as ``\(A\) and \(B\)'' \item Read \(A \cup B\) as ``\(A\) or \(B\)''. Note that unions (\(\cup\), ``or'') are always inclusive. \(A\cup B\) occurs if \(A\) occurs but \(B\) does not, \(B\) occurs but \(A\) does not, or both \(A\) and \(B\) occur. \end{itemize} \item An event \(A\) is a set. The collection \(\mathcal{F}\) is a \emph{collection of sets}. \item While an event is always a set, it can be a set consisting of a single outcome, or no outcomes at all (the empty set \(\emptyset\)). \item A collection of events \(A_1, A_2, \ldots\) are \textbf{disjoint} (a.k.a. mutually exclusive) if \(A_i \cap A_j = \emptyset\) for all \(i \neq j\). Events are disjoint if they have no outcomes in common. \end{itemize} As an example, consider a single roll of a four-sided die. The sample space consists of the four possible outcomes \(\Omega = \{1, 2, 3, 4\}\). Any subset of this sample space is an event. The following table lists he collection of all events (\(\mathcal{F}\)), and whether they occur if the single roll results in a 3 (that is, for the outcome \(\omega=3\)). \begin{longtable}[]{@{}lll@{}} \toprule Event & Description & Occurs upon outcome \(\omega=3\)?\tabularnewline \midrule \endhead \(\emptyset\) & Roll nothing (not possible) & No\tabularnewline \(\{1\}\) & Roll a 1 & No\tabularnewline \(\{2\}\) & Roll a 2 & No\tabularnewline \(\{3\}\) & Roll a 3 & Yes\tabularnewline \(\{4\}\) & Roll a 4 & No\tabularnewline \(\{1, 2\}\) & Roll a 1 or a 2 & No\tabularnewline \(\{1, 3\}\) & Roll a 1 or a 3 & Yes\tabularnewline \(\{1, 4\}\) & Roll a 1 or a 4 & No\tabularnewline \(\{2, 3\}\) & Roll a 2 or a 3 & Yes\tabularnewline \(\{2, 4\}\) & Roll a 2 or a 4 & No\tabularnewline \(\{3, 4\}\) & Roll a 3 or a 4 & Yes\tabularnewline \(\{1, 2, 3\}\) & Roll a 1, 2, or 3 (a.k.a. do not roll a 4) & Yes\tabularnewline \(\{1, 2, 4\}\) & Roll a 1, 2, or 4 (a.k.a. do not roll a 3) & No\tabularnewline \(\{1, 3, 4\}\) & Roll a 1, 3, or 4 (a.k.a. do not roll a 2) & Yes\tabularnewline \(\{2, 3, 4\}\) & Roll a 2, 3, or 4 (a.k.a. do not roll a 1) & Yes\tabularnewline \(\{1, 2, 3, 4\}\) & Roll something & Yes\tabularnewline \bottomrule \end{longtable} \begin{example} \protect\hypertarget{exm:dice-event}{}{\label{exm:dice-event} }Roll a four-sided die \emph{twice}, and record the result of each roll in sequence. For example, the outcome \((3, 1)\) represents a 3 on the first roll and a 1 on the second; this is not the same outcome as \((1, 3)\). \end{example} \begin{enumerate} \def\labelenumi{\arabic{enumi}.} \tightlist \item Identify the sample space. \item Identify \(A\), the event that the sum of the two dice is 4. \item Identify \(B\), the event that the sum of the two dice is at most 3. \item The previous events consider the sum of the two dice. Explain why we don't just consider the sample space to be \(\{2, \ldots, 8\}\), so that for example \(B = \{2, 3\}\). \item Identify \(C\), the event that the larger of the two rolls (or the common roll if a tie) is 3 \item Identify and interpret \(A\cap C\). \item Identify \(D\), the event that the first roll is a 3. \item Identify \(E\), the event that the second roll is a 3. \item Indetify and interpret \(D \cap E\). \item Identify and interpret \(D \cup E\). \item If the outcome is \((1, 3)\), which of the events above occurred? \end{enumerate} \begin{solution} \iffalse{} {Solution. } \fi{}to Example \ref{exm:dice-event} \end{solution} \begin{enumerate} \def\labelenumi{\arabic{enumi}.} \tightlist \item The sample space consists of 16 possible ordered pairs of rolls \begin{align*} \Omega & = \{(1, 1), (1, 2), (1, 3), (1, 4), (2, 1), (2, 2), (2, 3), (2, 4),\\ & \quad (3, 1), (3, 2), (3, 3), (3, 4), (4, 1), (4, 2), (4, 3), (4, 4)\} \end{align*} \item \(A=\{(1, 3), (2, 2), (3, 1)\}\) is the event that the sum of the two dice is 4. \item \(B=\{(1, 1), (1, 2), (2, 1)\}\) is the event that the sum of the two dice is at most 3. \item We might be interested in events other than ones that involve the sum of the dice, like those in the following parts. Knowing just the sum of the dice does not provide enough information to investigate such events. \item \(C=\{(1, 3), (2, 3), (3, 1), (3, 2), (3, 3)\}\), the event that the larger of the two rolls (or the common roll if a tie) is 3 \item \(A\cap C=\{(1, 3), (3, 1)\}\) is the event that both the sum of the two dice is 4 and the larger of the two rolls is 3. \item \(D=\{(3, 1), (3, 2), (3, 3), (3, 4)\}\), the event that the first roll is a 3. Note that each outcome in the sample space consists of a pair of rolls, so we must account for both rolls in defining events, even if the event of interest involves just the first roll. There is always a single sample space upon which all events are defined. \item \(E=\{(1, 3), (2, 3), (3, 3), (4, 3)\}\), the event that the second roll is a 3. Note that this is not the same event as \(D\). \item \(D \cap E = \{(3, 3)\}\) is the event that both rolls result in a 3. While an event is always a set, it can be a set consisting of a single outcome (or the empty set). \item \(D \cup E = \{(3, 1), (3, 2), (3, 3), (3, 4), (1, 3), (2, 3), (4, 3)\}\) is the event that at least one of the two rolls results in a 3. Notice that the union is inclusive: \((3, 3)\) is an element of \(D\cup E\). But also notice that the outcome \((3, 3)\) only appears once in the set \(D \cup E\). \item If the outcome is \((1, 3)\) then events \(A\), \(C\), \(A\cap C\), \(E\), \(D\cup E\) all occur. Events \(B\), \(D\), and \(D\cap E\) do not occur. \end{enumerate} \begin{example} \protect\hypertarget{exm:coin-event}{}{\label{exm:coin-event} }Flip a coin 4 times, and record the result of each trial in sequence. For example, HTTH means heads on the first on last trial and tails on the second and third. \end{example} \begin{enumerate} \def\labelenumi{\arabic{enumi}.} \tightlist \item Specify the sample space. \item Identify \(A\), the event that exactly 3 of the flips land on heads. \item Identify \(B\), the event that exactly 4 of the flips land on heads. \item Identify \(C\), the event that the at least 3 of the flips land on heads. How does \(C\) relate to \(A\) and \(B\)? \item The previous events all consider the number of heads flipped. Explain why we don't just consider the sample space to be \(\{0, 1, 2, 3, 4\}\), so that for example \(C = \{3, 4\}\). \item Identify \(D\), the event that at least 3 heads are flipped in a row. \item Identify \(E\), the event that the first two flips results in tails. \item Identify \(D\cap E\). \item If the outcome is HHTH, which of the events above occurred? \end{enumerate} \begin{solution} \iffalse{} {Solution. } \fi{}to Example \ref{exm:coin-event} \end{solution} \begin{enumerate} \def\labelenumi{\arabic{enumi}.} \tightlist \item The sample space is composed of 16 outcomes \begin{align*} \Omega & = \{HHHH, HHHT, HHTH, HTHH, THHH, HHTT, HTHT, HTTH,\\ & \qquad THHT, THTH, TTHH, HTTT, THTT, TTHT, TTTH, TTTT\} \end{align*} \item \(A = \{HHHT, HHTH, HTHH, THHH\}\) is the event that exactly 3 of the flips land on heads \item \(B = \{HHHH\}\), the event that exactly 4 of the flips land on heads. While an event is always a set, it can be a set consisting of a single outcome. \item \(C = \{HHHT, HHTH, HTHH, THHH, HHHH\}\) is the event that the at least 3 of the flips land on heads. Also \(C = A \cup B\). \item Yes, the previous events all consider the number of heads flipped, but we might be interested in events --- like the ones in the following parts --- whose occurrence cannot be determined simply by knowing the number of heads. The sample space should always to defined in such a way to provide enough information to investigate any relevant event of interest. There is always a single sample space upon which all events are defined. \item \(D = \{HHHT, THHH, HHHH\}\) is the event that at least 3 heads are flipped in a row. Note that \(D\) is not the same event as \(C\). \item \(E = \{TTHH, TTHT, TTTH, TTTT\}\) is the event that the first two flips result in tails. Note that each outcome consists of the results of 4 flips, so we must account for all 4 flips in defining events. There is always a single sample space upon which all events are defined. \item \(D\cap E=\emptyset\) so the events \(D\) and \(E\) are disjoint; it is not possible to have at least three heads in a row when the first two flips (out of 4) are tails. \item If the outcome is HHTH then events \(A\) and \(C\) occur. Events \(B\), \(D\), \(E\), and \(D \cap E\) do not occur. \end{enumerate} \begin{example}[Matching problem] \protect\hypertarget{exm:matching-event}{}{\label{exm:matching-event} \iffalse (Matching problem) \fi{} }So-called ``matching problems'' concern the following generic scenario. A set of \(n\) cards labeled \(1, 2, \ldots, n\) are placed in \(n\) boxes labeled \(1, 2, \ldots, n\), with exactly one card in each box. Typical questions of interest involve whether the number of a card matches the number of the box in which it is placed. (More colorful descriptions include \href{http://www.rossmanchance.com/applets/randomBabies/RandomBabies.html}{returning babies at random to mothers} or \href{https://fivethirtyeight.com/features/everythings-mixed-up-can-you-sort-it-all-out/}{placing rocks at random back on a museum shelf}.) Consider the case \(n=4\). \end{example} \begin{enumerate} \def\labelenumi{\arabic{enumi}.} \tightlist \item Identify a reasonable sample space. \item Specify the event that all cards match their box. \item Specify the event that no cards match their box. \item Specify the event that exactly 3 cards match their box. \item Specify the event that card 3 is placed in box 3. \end{enumerate} \begin{solution} \iffalse{} {Solution. } \fi{}to Example \ref{exm:matching-event} \end{solution} \begin{enumerate} \def\labelenumi{\arabic{enumi}.} \tightlist \item We can consider each outcome to be a particular placement of cards in the boxes. For example, the outcome 3214 (or \((3, 2, 1, 4)\)) represents that card 3 is placed in box 1, card 2 in box 2, card 1 in box 3, and card 4 in box 4. So the sample space consists of the following 24 outcomes\footnote{There are 4 cards that could potentially go in box 1, then 3 cards that could potentially go in box 2, 2 to box 3, and 1 left for box 4. This results in \(4\times3\times2\times1=4! = 24\) possible outcomes. We will see more counting rules in Chapter \ref{counting}}. \begin{align*} \Omega & = \{1234, 1243, 1324, 1342, 1423, 1432 \\ & \qquad 2134, 2143, 2314, 2341, 2413, 2431 \\ & \qquad 3124, 3142, 3214, 3241, 3412, 3421 \\ & \qquad 4123, 4132, 4213, 4231, 4312, 4321\} \end{align*} \item \(A=\{1234\}\) is the event that all cards match their box. While an event is always a set, it can be a set consisting of a single outcome (or the empty set). \item \(B=\{2143, 2341, 2413, 3142, 3412, 3421, 4123, 4312, 4321\}\) is the event that no cards match their box. \item \(\emptyset\) is the event in which exactly 3 cards match their box. There are no outcomes in which exactly 3 cards match; if three cards match, then the fourth card must necessarily match too. \item \(C=\{1234, 1432, 2134, 2431, 4132, 4231\}\) is the event that card 3 is placed in box 3. Since our sample space consists of the placements of each of the cards, each event must be expressed in terms of these outcomes. \end{enumerate} Remember that intervals of real numbers such as \((a,b), [a,b], (a,b]\) are also sets, and so can also be events. \begin{example} \protect\hypertarget{exm:sat-event}{}{\label{exm:sat-event} }Consider as a sample space all possible scores on the SAT Math exam (ranging from 200 to 800). Even though actual scores are multiples of 10, it is mathematically convenient to consider the sample space as \(\Omega=[200, 800]\), the set of all real numbers between 200 and 800 (rather than \(\{200, 210, 220, \ldots, 800\}\).) \end{example} 1. Identify \(A\), the event that an SAT Math score is at most 700. 1. Identify \(B\), the event that an SAT Math score is greater than 500. 1. Identify and interpret \(A\cap B\). \begin{solution} \iffalse{} {Solution. } \fi{}to Example \ref{exm:sat-event} \end{solution} \begin{enumerate} \def\labelenumi{\arabic{enumi}.} \tightlist \item \(A=[200, 700]\) is the event that an SAT Math score is at most 700. \item \(B=(500, 800]\) is the event that an SAT Math score is greater than 500. \item \(A\cap B = (500, 700]\) is the event that an SAT Math score is greater than 500 but at most 700. \end{enumerate} \begin{example} \protect\hypertarget{exm:uniform-event}{}{\label{exm:uniform-event} } Suppose the spinner in Figure \ref{fig:uniform-spinner} is spun twice. Let the sample space be \(\Omega = [0,1]\times [0,1]\). Represent each of the following events using set notation, but also sketch a picture. (Hint: represent the sample space as a square.) \end{example} \begin{enumerate} \def\labelenumi{\arabic{enumi}.} \tightlist \item Identify \(A\), the event that the first spin is larger then the second. \item Identify \(B\), the event that the smaller of the two spins (or common value if a tie) is less than 0.5. \item Identify \(C\), the event that the sum of the two dice is less than 1.5. \item Identify \(D\), the event that the first spin is less than 0.4. \end{enumerate} \begin{solution} \iffalse{} {Solution. } \fi{} to Example \ref{exm:uniform-event} \end{solution} \begin{enumerate} \def\labelenumi{\arabic{enumi}.} \tightlist \item \(A = \{(\omega_1, \omega_2): \omega_1>\omega_2\}\) is the event that the first spin is larger then the second. Note: we only consider \((\omega_1, \omega_2)\) in the sample space \([0, 1]\times[0,1]\); the conditions \(0\le \omega_1 \le 1, 0\le \omega_2 \le 1\) are assumed.\\ \item \(B = \{(\omega_1, \omega_2): \min(\omega_1,\omega_2)<0.5\}\) is the event that the smaller of the two spins (or common value if a tie) is less than 0.5. This is equivalent to the event that at least one of the spins is less than 0.5 \(B = \{(\omega_1, \omega_2): \omega_1<0.5 \text{ or } \omega_2<0.5\} = ([0.5, 1]\times[0.5, 1])^c\). \item \(C = \{(\omega_1, \omega_2): \omega_1+\omega_2\ge 1.5\} = \{(\omega_1, \omega_2): \omega_2\ge 1.5-\omega_1\}\) is the event that the sum of the two dice is at least 1.5. \item \(D = \{(\omega_1, \omega_2): \omega_1<0.4\}\) is the event that the first spin is less than 0.4. Remember, sample space outcomes are pairs of spins. \end{enumerate} \begin{figure} \centering \includegraphics{bookdown-demo_files/figure-latex/uniform-event-plot-1.pdf} \caption{\label{fig:uniform-event-plot}Illustration of the events in Exercise \ref{exm:uniform-event}. The square represents the sample space \(\Omega=[0,1]\times[0,1]\).} \end{figure} \begin{example}[Don't do what Donny Don't does.] \protect\hypertarget{exm:dd-event}{}{\label{exm:dd-event} \iffalse (Don't do what Donny Don't does.) \fi{} }Donny Don't is asked a series of questions involving a pair of rolls of six-sided dice, such as ``what is the event that the sum of the dice is at least 10''. Donny's responses are below; explain to him what is wrong with his responses and help him see the correct answers. \end{example} \begin{enumerate} \def\labelenumi{\arabic{enumi}.} \tightlist \item The possible rolls are 1 through 6, so the sample space is \(\{1, 2, 3, 4, 5, 6\}\). \item The sum of the two dice can be 2 through 12, so the event that the sum of the two dice is at least 10 is \(\{10, 11, 12\}\). \item The event that the first roll is a 3 is \(\{3\}\). \item The event that the first roll is a 3 and the second roll is a 1 is \(\{3, 1\}\) \item Donny's sample space from the first question might correspond to what dice rolling scenario? What does \(\{3, 1\}\) represent in this scenario? \end{enumerate} \begin{solution} \iffalse{} {Solution. } \fi{}to Example \ref{exm:dd-event} \end{solution} \begin{enumerate} \def\labelenumi{\arabic{enumi}.} \tightlist \item The questions involve a pair of rolls, so best to record an outcome as an ordered pair, e.g., (5, 2) for 5 on the first roll and 2 on the second. Therefore, the sample space would be the following set of 36 possible outcomes. \begin{align*} \Omega = & \{ (1, 1), (1, 2), \ldots, (1, 6),\\ & \;\; (2, 1), (2, 2), \ldots, (2, 6),\\ & \;\; \vdots\qquad \qquad \quad \cdots \qquad \vdots\\ & \;\; (6, 1), (6, 2), \ldots, (6, 6) \} \end{align*} \item Donny's answers to the first two parts are inconsistent, since there is always a single sample space. So if he says the answer to the first part is \(\{1, \ldots, 6\}\), then any event must be a subset of that sample space and his answer to the second part must be wrong. Using the sample space of 36 ordered pairs from the previous answer, the correct event that the sum of the two dice is at least 10 is \[ \{(4, 6), (5, 5), (5, 6), (6, 4), (6, 5), (6, 6)\} \] If Donny's sample space in the first part had been \(\{2, \ldots, 12\}\), corresponding to the sum of the two dice, then his answer of \(\{10, 11, 12\}\) would have been correct. However, using such a sample space, he would not have been able to answer the remaining questions (which don't involve the sum of the rolls). There is always one sample space on which all events are defined. \item Donny didn't take into account that an outcome is a pair of rolls. The correct event is \(\{(3, 1), (3, 2), (3, 3), (3, 4), (3, 5), (3, 6)\}\), the set of all pairs of rolls for which the first roll is 3. \item Maybe Donny is just using bad notation here, but it sure looks like he is confusing an outcome with an event. The answer should be \(\{(3, 1)\}\), the set containing the single outcome \((3, 1)\). Notice that this is not the same set as \(\{(1, 3)\}\). (But the set \(\{3, 1\}\) is the same as the set \(\{1, 3\}\).) \item The sample space of \(\{1, 2, 3, 4, 5, 6\}\) could correspond to a \emph{single} roll of a fair six-sided die. In this case, the event \(\{3, 1\}\) would be the event that the roll is either a 3 or a 1. (The set \(\{3, 1\}\) is the same as the set \(\{1, 3\}\).) \end{enumerate} \begin{example}[Don't do what Donny Don't does.] \protect\hypertarget{exm:dd-events}{}{\label{exm:dd-events} \iffalse (Don't do what Donny Don't does.) \fi{} } At various points in his homework, Donny Don't writes the following. Explain to Donny, both mathematically and intuitively, why each of the following symbols is nonsense. Below, \(A\) and \(B\) represent events, \(X\) and \(Y\) represent random variables. \end{example} \begin{enumerate} \def\labelenumi{\arabic{enumi}.} \tightlist \item \(\IP(A = 0.5)\) \item \(\IP(A + B)\) \item \(\IP(A) \cup \IP(B)\) \item \(\IP(X)\) \item \(\IP(X = A)\) \item \(\IP(X \cap Y)\) \end{enumerate} \begin{solution} \iffalse{} {Solution. } \fi{}to Example \ref{exm:dd-events} \end{solution} \begin{enumerate} \def\labelenumi{\arabic{enumi}.} \tightlist \item \(A\) is a set and 0.5 is a number; it doesn't make mathematical sense to equate them. Suppose that \(A\) is the event that is rains tomorrow. It doesn't make sense to say (as \(A=1\) does) ``it rains tomorrow equals 0.5''. If we want to say ``the probability that it rains tomorrow equals 0.5'' we should write \(\IP(A) = 0.5\). \item \(A\) and \(B\) are sets; it doesn't make mathematical sense to add them. Suppose that \(B\) is the event that tomorrow's high temperature is above 80 degrees F. It doesn't make sense to say (as \(A+B\) does) ``the sum of (it rains tomorrow) and (tomorrow's high temperature is above 80 degrees F)''. If we want ``(it rains tomorrow) OR (tomorrow's high temperature is above 80 degrees F)'', then we need \(A\cup B\). Union is an operation on sets; addition is an operation on numbers. \item \(\IP(A)\) and \(\IP(B)\) are numbers; union is an operation on sets, it doesn't make mathematical sense to take a union of numbers. Since \(\IP(A)\) and \(\IP(B)\) are numbers then mathematically we can add them. But keep in mind that \(\IP(A)+\IP(B)\) is not necessarily a probability, for example if \(\IP(A)=0.5\) and \(\IP(B)=0.6\). If we want ``the probability that (it rains tomorrow) OR (tomorrow's high temperature is above 80 degrees F)'' then the correct symbol is \(\IP(A\cup B)\), which would be equal to \(\IP(A)+\IP(B)\) only if \(A\) and \(B\) were disjoint (which in the example would mean it's not possible to have a rainy day with a high temperature above 80 degrees F). \item \(X\) is a random variable, and probabilities are assigned to events. If \(X\) is tomorrow's high temperature in degrees F then \(P(X)\) reads ``the probability that tomorrow's high temperature in degrees F'', which is missing any qualifying information that could define an event. We could write \(\IP(X>80)\) to represent ``the probability that (tomorrow's high temperature is greater than 80 degrees F)''. \item \(X\) is a random variable (a function) and \(A\) is an event (a set), and it doesn't make sense to equate these two different mathematical objects. It doesn't make sense to say (as \(X=A\) does) ``tomorrow's high temperature in degrees F equals the event that it rains tomorrow''. \item \(X\) and \(Y\) are RVs (functions) and intersection is an operation on sets. If \(Y\) is the amount of rainfall in inches tomorrow then \(X \cap Y\) is attempting to say ``tomorrow's high temperature in degrees F and the amount of rainfall in inches tomorrow'', but this is still missing qualifying information to define a valid event for which a probability can be assigned. We could say \(\IP(\{X > 80\} \cap \{Y < 2\})\) to represent ``the probability that (tomorrow's high temperature is greater than 80 degrees F) AND (the amount of rainfall tomorrow is less than 2 inches)''. \end{enumerate} \hypertarget{rv}{% \section{Random variables}\label{rv}} Statisticians use the terms \emph{observational unit} and \emph{variable}. Observational units are the people, places, things, etc., for which data are observed. Variables are the measurements made on the observational units. For example, the observational units in a study could be college students, while variables could be high school GPA, college GPA, SAT score, years in college, number of Statistics courses taken, etc. In probability, an \emph{outcome} of a random phenomenon plays a role analogous to an observational unit in statistics. The sample space of outcomes is often only vaguely defined. In many situations we are less interested in detailing the outcomes themselves and more interested in whether or not certain events occur, or with measurements that we can make for the outcomes. For example, if the random phenomenon corresponds to randomly selecting a random sample of students at a college, an outcome could be the list of students selected for the sample. But we are less interested in who the students are, and more interested in questions which involve variables, such as: what is the distribution of SAT scores? What is the relationship between high school GPA and college GPA? What is the average number of years before graduation? Roughly, a \emph{random variable} assigns a number to each outcome of a random phenomenon. More precisely \begin{definition} \protect\hypertarget{def:rv}{}{\label{def:rv} } A \textbf{random variable (RV)} \(X\) is a \emph{function} that takes an outcome in the sample space as input and returns a real number as output; that is, \(X:\Omega \mapsto \mathbb{R}\). Random variables are typically denoted by capital letters near the end of the alphabet, with or without subscripts: e.g.~\(X\), \(Y\), \(Z\), or \(X_1\), \(X_2\), \(X_3\), etc. The value that the random variable \(X\) assigns to the outcome \(\omega\) is denoted \(X(\omega)\). \end{definition} \begin{example} \protect\hypertarget{exm:coin-rv}{}{\label{exm:coin-rv} } Flip a coin 4 times, and record the result of each trial in sequence. For example, HTTH means heads on the first on last trial and tails on the second and third. One random variable is \(X\), the number of heads flipped. \end{example} \begin{enumerate} \def\labelenumi{\arabic{enumi}.} \tightlist \item Explain why \(X\) is a random variable. \item Evaluate each of the following: \(X(HHHH), X(HTHT), X(TTHH)\). \item Identify the possible values of \(X\). Why not let the sample space just consist of this set of possible values? \end{enumerate} \begin{solution} \iffalse{} {Solution. } \fi{}to Example \ref{exm:coin-rv} \end{solution} \begin{enumerate} \def\labelenumi{\arabic{enumi}.} \tightlist \item \(X\) maps each outcome to a number via the function ``count the number of heads''. \item \(X(HHHH) = 4, X(HTHT) = 2, X(TTHH) = 2\). \item The possible values of \(X\) are \(0, 1, 2, 3, 4\). You might ask: if we only care about the number of heads, why bother with the coin flip sequence at all? That is, why not define the sample space as \(\{0, 1, 2, 3, 4\}\) rather than \(\{HHHH, HHHT, HHTH, \ldots\}\). The main reason why is that we often want to define many random variables on the same sample space, and study the relationships between random variables. For example, if a sample space outcome were just the number of heads, we would not be able to obtain information about the longest number of heads in a row, or the proportion of heads on trials that follow heads. Moreover we would not be able to study the relationship between random variables unless they were defined on a common sample space. As a statistics analogy, you would not be able to study the relationship between SAT scores and college GPA unless you measured both variables for the same set of observational units. (Another but less important reason is that is often convenient to work with probability spaces in which the outcomes are equally likely, as is the case for \(\{HHHH, HHHT, HHTH, \ldots\}\) but not for \(\{0, 1, 2, 3, 4\}\), for four flips of a fair coin.) \end{enumerate} The RV itself is typically denoted with a capital letter (\(X\)); possible values of that random variable are denoted with lower case letters (\(x\)). Think of the capital letter \(X\) as a label standing in for a formula like ``the number of heads in 4 flips of a coin'' and \(x\) as a dummy variable standing in for a particular value like 3. We are often interested in events which involve random variables. For example, the expressions \(X=x\) or \(\{X=x\}\) are shorthand for the \emph{event} \(\{\omega\in\Omega: X(\omega)=x\}\), the set of outcomes \(\omega\) for which \(X(\omega)=x\). Remember that any event is a subset of the \emph{sample space}. So objects like \(\{X=x\}\) are subsets\footnote{Technically, we have some collection \(\mathcal{F}\) of events of interest, and so we require sets like \(\{X\le x\}\) to be in \(\mathcal{F}\). This requirement is satified by requiring \(X\) to be an \emph{\(\mathcal{F}\)-measurable} function.} of \(\Omega\). \begin{example} \protect\hypertarget{exm:coin-rv-event}{}{\label{exm:coin-rv-event} }Flip a coin 4 times, and record the result of each trial in sequence. For example, HTTH means heads on the first on last trial and tails on the second and third. One random variable is \(X\), the number of heads flipped. \end{example} \begin{enumerate} \def\labelenumi{\arabic{enumi}.} \tightlist \item Identify and interpret the event \(\{X=3\}\). That is, identify the outcomes \(\omega\) for which \(X(\omega)=3\). \item Identify and interpret the event \(\{X=4\}\). \item Identify and interpret the event \(\{X\ge3\}\). How is this event related to the previous two? \end{enumerate} \begin{solution} \iffalse{} {Solution. } \fi{}to Example \ref{exm:coin-rv-event} \end{solution} \begin{enumerate} \def\labelenumi{\arabic{enumi}.} \tightlist \item \(\{X=3\} = \{HHHT, HHTH, HTHH, THHH\}\) is the event that exactly 3 of the flips land on heads. This is an event because it is a subset of the sample space. \item \(\{X=4\}= \{HHHH\}\), the event that exactly 4 of the flips land on heads. Notice that the event is the set \(\{HHHH\}\), which consists of the single outcome \(HHHH\). \item \(\{X\ge3\} = \{HHHT, HHTH, HTHH, THHH, HHHH\}\) is the event that the at least 3 of the flips land on heads. Also \(\{X\ge 3\} = \{X=3\}\cup \{X=4\}\). \end{enumerate} Recall that for a mathematical function\footnote{Throughout, we use \(g\) to denote a generic function, and reserve \(f\) to represent a probability density function. Likewise, we represent a generic function argument (or ``dummy variable'') with \(u\), since \(x\) is often used to represent possible values of a random variable \(X\); in the RV scenario \(x\) typically represents the \emph{output} of the function \(X\) rather than the input (which is a sample space outcome \(\omega\).)} \(g\), given an input \(u\), the function returns a real number \(g(u)\). For example, if \(g(u) = u^2\) then \(g(3) = 9\). If the input comes from some set \(S\) (i.e.~\(u\in S\)), we often write \(g:S\mapsto \mathbb{R}\). Likewise, a random variable \(X\) is a function which maps each outcome \(\omega\) in the sample space \(\Omega\) to a real number \(X(\omega)\); \(X:\Omega\mapsto\mathbb{R}\). For a single outcome \(\omega\), the value \(x = X(\omega)\) is a single number; notice that \(x\) represents the \emph{output} of the function \(X\) rather than the input. However, it is important to remember that the RV \(X\) itself is a \emph{function}, and \emph{not} a single number. You are probably familiar with functions which have simple closed form formulas of their arguments: \(g(u)=5u\), \(g(u)=u^2\), \(g(u)=e^u\), etc. While any random variable is some function, the function is rarely specified as an explicit mathetical formula of its input \(\omega\). Often, outcomes are not even numbers (e.g., sequences of coin flips), or only vaguely specified if at all (e.g., possible paths of a hurricane). In the coin flip example, we defined \(X\) only through the words ``number of flips that land on heads''; translating even this simple situation into a formula of \(\omega\) requires some notation\footnote{It's easiest if we label a flip of heads as 1 and tails as 0. Represent an outcome \(\omega\) as \((\omega_1, \omega_2, \omega_3, \omega_4)\), where \(\omega_i\in\{0,1\}\) is the result of the \(i\)th flip. Then \(X(\omega)=\sum_{i=1}^{4} \omega_i\) represents the number of heads. For example, outcome HHTH would be represented as \((1, 1, 0, 1)\) and \(X((1, 1, 0, 1)) = 1 + 1 + 0 + 1 = 3\). This could be coded as \texttt{sum(omega)}.}. It is more appropriate to think of a RV as a function in the sense of a scale at a grocery store which maps a fruit to its weight, \(X: \text{fruit}\mapsto\text{weight}\). Put an apple on the scale and the scale returns a number, \(X(\text{apple})\), the weight of the apple. Likewise, \(X(\text{orange})\), \(X(\text{banana})\). The RV \(X\) is the scale itself. (This simplistic analogy assumes a sample space outcome is a single fruit. Of course, it's even more complicated in reality since an outcome can be considered a set of fruits, so that we have for example \(X(\{\text{2 apples}, \text{3 oranges}\})\), and all fruits do not weigh the same, so that \(X(\text{this apple})\) is not the same as \(X(\text{that apple})\).) The RV itself is denoted with a capital letter; possible values of that random variable are denoted with lower case letters. For example \(\{X=x\}\) is shorthand for the event \(\{\omega\in\Omega: X(\omega)=x\}\), the set of outcomes \(\omega\) for which \(X(\omega)=x\). Think of the capital letter \(X\) as a label standing in for a formula like ``the number of heads in 4 flips of a coin'' and \(x\) as a dummy variable standing in for a particular value like 3. Remember that any event is a subset of the \emph{sample space}. So objects like \(\{X=x\}\) are subsets\footnote{Technically, we have some collection \(\mathcal{F}\) of events of interest, and so we require sets like \(\{X\le x\}\) to be in \(\mathcal{F}\). This requirement is satified by requiring \(X\) to be an \emph{\(\mathcal{F}\)-measurable} function.} of \(\Omega\). In the scale analogy if \(X\) is weight measured in pounds, we might have \(\{X>5\}=\{\text{watermelon}, \text{pineapple}\}\) is the set of fruits that weigh more than 5 pounds. \begin{example} \protect\hypertarget{exm:dice-rv}{}{\label{exm:dice-rv} }Roll a four-sided die twice, and record the result of each roll in sequence. For example, the outcome \((3, 1)\) represents a 3 on the first roll and a 1 on the second; this is not the same outcome as \((1, 3)\). Let \(X\) be the sum of the two dice, and let \(Y\) be the larger of the two rolls (or the common value if both rolls are the same). \end{example} \begin{enumerate} \def\labelenumi{\arabic{enumi}.} \tightlist \item Evaluate \(X((1, 3))\), \(X((4, 3))\), and \(X((2,2))\). \item Evaluate \(Y((1, 3))\), \(Y((4, 3))\), and \(Y((2,2))\). \item Identify and interpret \(\{X = 4\}\). \item Identify and interpret \(\{X = 3\}\). \item Identify and interpret \(\{X \le 3\}\). \item Identify and interpret \(\{Y = 4\}\). \item Identify and interpret \(\{Y = 3\}\). \item Identify and interpret \(\{Y \le 3\}\). \item Identify and interpret \(\{X = 4, Y = 3\}\) (that is, \(\{X = 4\}\cap \{Y = 3\}\)). \item Identify and interpret \(\{X = 4, Y \le 3\}\). \item Identify and interpret \(\{X = 3, Y = 3\}\). \item Identify and interpret \(\{X \ge Y\}\). \item Identify the possible values of \(X\). \item Identify the possible values of \(Y\). \item Identify the possible values of the pair \((X, Y)\). \end{enumerate} \begin{solution} \iffalse{} {Solution. } \fi{}to Example \ref{exm:dice-rv} \end{solution} \begin{enumerate} \def\labelenumi{\arabic{enumi}.} \tightlist \item \(X\) is the sum of the two rolls, so \(X((1, 3))=4\), \(X((4, 3))=7\), and \(X((2,2))=4\). \item \(Y\) is the larger of the two rolls (or the common value if a tie) so \(Y((1, 3))=3\), \(Y((4, 3))=4\), and \(Y((2,2))=2\). \item \(\{X = 4\} =\{(1, 3), (2, 2), (3, 1)\}\) is the event that the sum of the two dice is 4. \item \(\{X = 3\} =\{(1, 2), (2, 1)\}\) is the event that the sum of the two dice is 3. \item \(\{X \le 3\}=\{(1, 1), (1, 2), (2, 1)\}\) is the event that the sum of the two dice is at most 3. \item \(\{Y = 4\}=\{(1, 4), (2, 4), (3, 4), (4, 4), (4, 1), (4, 2), (4,3)\}\) is the event that the larger of the two rolls is 4. \item \(\{Y = 3\}=\{(1, 3), (2, 3), (3, 3), (3, 1), (3, 2)\}\) is the event that the larger of the two rolls is 3. \item \(\{Y \le 3\}=\{(1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3), (3, 1), (3, 2), (3, 3)\}\) is the event that the larger of the two rolls is at most 3. Notice that since in this example \(Y\) can only take values 1, 2, 3, 4, we have \(\{Y\le 3\} = \{Y=4\}^c\). \item \(\{X = 4, Y = 3\} \equiv \{X = 4\}\cap \{Y = 3\}=\{(1, 3), (3, 1)\}\) is the event that both the sum of the two dice is 4 and the larger of the two rolls is 3. Even though this involves two random variables, it is a single event (that is, a single subset of the sample space). There are only two outcomes for which both the sum of the two dice is 4 and the larger of the two dice is 3. \item \(\{X = 4, Y \le 3\} \equiv \{X = 4\}\cap \{Y \le 3\}=\{(1, 3), (2, 2), (3, 1)\}\) is the event that both the sum of the two dice is 4 and the larger of the two rolls is at most 3. Notice that since in this example \(\{X=4\} \subset \{Y\le 3\}\), we have \(\{X = 4, Y \le 3\} = \{X=4\}\). \item \(\{X = 3, Y = 3\} \equiv \{X = 3\}\cap \{Y = 3\}=\emptyset\), since there are no outcomes for which both the sum is 3 and the larger of the two dice is 3. (If the the larger of the two dice is 3, then the sum must be at least 4.) \item The event \(\{X\ge Y\}\) represents the set of outcomes \(\{\omega: X(\omega) \ge Y(\omega)\}\). In this example, for every possible outcome the sum of the two dice is at least as large as the larger of the two die, so \(\{X \ge Y\} = \Omega\). \item The possible values of \(X\) are \(\{2, 3, \ldots, 8\}\) \item The possible values of \(Y\) are \(\{1, 2, 3, 4\}\) \item The possible values of the pair \((X, Y)\) are \(\{(2, 1), (3, 2), (4, 2), (4, 3), (5, 3), (5, 4), (6, 3), (6, 4), (7, 4), (8,4)\}\). Notice that while, for example, 8 is a possible value of \(X\) and 1 is a possible value of \(Y\), (8, 1) is not a possible value of the pair \((X, Y)\); it's not possible for the larger of the two dice to be 1 but their sum to be 8. \end{enumerate} When dealing with probabilities, it is common to write \(\IP(X=3)\) instead of \(\IP(\{X=3\})\), and \(\IP(X = 4, Y = 3)\) instead of \(\IP(\{X = 4\}\cap \{Y = 3\})\); read the comma in \(\IP(X = 4, Y = 3)\) as ``and''. But keep in mind that an expression like ``\(X=3\)'' really represents an event \(\{X=3\}\), an expression which itself represents \(\{\omega\in\Omega: X(\omega) = 3\}\), a subset of \(\Omega\). \begin{example} \protect\hypertarget{exm:PP-rv}{}{\label{exm:PP-rv} } Customers enter a deli and take a number to mark their place in line. When the deli opens the counter starts 0; the first customer to arrive takes number 1, the second 2, etc. We record the counter over time, continuously, as it changes as customers arrive. Time is measured in minutes after the deli opens (time 0). A sample space outcome could be represented as a path of the number of customers over time; a few such paths are illustrated in Figure \ref{fig:coin-sim2}. Notice the stairstep feature: a customer arrives and takes a number then the counter stays on that number for some time (the flat spots) until another customer arrives and the counter increases by one (the jumps). There are many random variables that could be interest, including \begin{itemize} \tightlist \item \(N_t\), the number of customers that have arrived by time \(t\), where \(t\ge0\) is minutes after time 0 \item \(T_j\), the time (in minutes after time 0) at which the \(j\)th customer arrives, for \(j=1, 2, \ldots\) \item \(W_j\), the ``waiting'' time (in minutes) between the arrival of the \(j\)th and the \((j-1)\)th customer. \end{itemize} \end{example} \begin{figure} \includegraphics[width=0.5\linewidth]{_graphics/PP-path-one} \includegraphics[width=0.5\linewidth]{_graphics/PP-path-several} \caption{Sample space outcomes for Example \ref{exm:PP-rv}. Left: a single sample path of the number of customer arrivals over time. Right: several possible paths.}\label{fig:PP-rv-plot} \end{figure} For the outcome represented by the path in the plot on the left in Figure \ref{fig:PP-rv-plot}, identify (as best as you can from the plot) the value of the following random variables. \begin{enumerate} \def\labelenumi{\arabic{enumi}.} \tightlist \item \(N_4\) \item \(N_{6.5}\) \item \(T_4\) \item \(T_5\) \item \(W_1\) \item \(W_5\) \end{enumerate} \begin{solution} \iffalse{} {Solution. } \fi{}to Example \ref{exm:PP-rv} \end{solution} \begin{enumerate} \def\labelenumi{\arabic{enumi}.} \tightlist \item For this outcome \(N_4=3\); the number of customers that have arrived by time 4 is 3. \item For this outcome \(N_{6.5}=5\); the number of customers that have arrived by time 6.5 is 5. The number of customers is a whole number, but time is measured continuously (e.g., 6.5 minutes after opening). \item For this outcome \(T_4\approx 5.1\). The path jumps to 4 a little after time 5, so the time at which the fourth customer arrives (when the counter jumps to 4) is about 5.1 minutes after open. \item For this outcome \(T_5\approx 5.9\). The path jumps to 5 a little before time 6, so the time at which the fifth customer arrives (when the counter jumps to 5) is about 5.9 minutes after open. \item For this outcome \(W_1\approx 2\). \(W_1\) is the waiting time from open until the first customer arrives, which seems to happen at about time 2 (when the counter jumps to 1). \item For this outcome \(W_5\approx 0.8\). \(W_5\) is the time elapsed between the arrival of the fourth (at time 5.1) and fifth (at time 5.9) customers, which is about 0.8 minutes. \end{enumerate} \begin{example}[Matching problem] \protect\hypertarget{exm:matching-rv}{}{\label{exm:matching-rv} \iffalse (Matching problem) \fi{} }So-called ``matching problems'' concern the following generic scenario. A set of \(n\) cards labeled \(1, 2, \ldots, n\) are placed in \(n\) boxes labeled \(1, 2, \ldots, n\), with exactly one card in each box. Typical questions of interest involve whether the number of a card matches the number of the box in which it is placed. (More colorful descriptions include \href{http://www.rossmanchance.com/applets/randomBabies/RandomBabies.html}{returning babies at random to mothers} or \href{https://fivethirtyeight.com/features/everythings-mixed-up-can-you-sort-it-all-out/}{placing rocks at random back on a museum shelf}.) Consider the case \(n=4\). Let \(Y\) be the number of cards (out of 4) which match the number of the box in which they are placed. For \(j=1, 2, 3, 4\), let \(I_j=1\) if card \(j\) is placed in box \(j\), and let \(I_j=0\) otherwise. \end{example} \begin{enumerate} \def\labelenumi{\arabic{enumi}.} \tightlist \item Evaluate \(Y(1234)\), \(Y(1243)\), and \(Y(2143)\). \item Evaluate \(I_1(1234)\), \(I_1(1243)\), and \(I_1(2143)\). \item Evaluate \(I_2(1234)\), \(I_2(1243)\), and \(I_2(2143)\). \item Evaluate \(I_3(1234)\), \(I_3(1243)\), and \(I_3(2143)\). \item Evaluate \(I_4(1234)\), \(I_4(1243)\), and \(I_4(2143)\). \item Identify and interpret \(\{Y=4\}\). \item Identify and interpret \(\{Y=0\}\). \item Identify and interpret \(\{Y=3\}\). \item Identify and interpret \(\{I_1=1\}\). \item Identify and interpret \(\{I_3=1\}\). \item What is the relationship between \(Y\) and the \(I_j\)'s? \end{enumerate} \begin{solution} \iffalse{} {Solution. } \fi{}to Example \ref{exm:matching-rv} \end{solution} \begin{enumerate} \def\labelenumi{\arabic{enumi}.} \tightlist \item \(Y\) counts the number of matches so \(Y(1234)=4\) (all numbers match), \(Y(1243)=2\) (1 and 2 match, 3 and 4 do not), and \(Y(2143)=0\) (no numbers match). \item \(I_1=1\) only if card 1 is in the first position, so \(I_1(1234)=1\), \(I_1(1243)=1\), and \(I_1(2143)=0\). \item \(I_2=1\) only if card 2 is in the second position, so \(I_2(1234)=1\), \(I_2(1243)=1\), and \(I_2(2143)=0\). \item \(I_3=1\) only if card 3 is in the third position, so \(I_3(1234)=1\), \(I_3(1243)=0\), and \(I_3(2143)=0\). \item \(I_4=1\) only if card 4 is in the fourth position, so \(I_4(1234)=1\), \(I_4(1243)=0\), and \(I_4(2143)=0\). \item \(\{Y=4\}=\{1234\}\) is the event that all 4 cards match. Notice that the event is the set \(\{1234\}\), which consists of the single outcome \(1234\). \item \(\{Y=0\}=\{2143, 2341, 2413, 3142, 3412, 3421, 4123, 4312, 4321\}\) is the event that none of the cards match \item \(\{Y=3\}=\emptyset\) is the event in which exactly 3 cards match their box. There are no outcomes in which exactly 3 cards match; if three cards match, then the fourth card must necessarily match too. \item \(\{I_1=1\}=\{1234, 1243, 1324, 1342, 1423, 1432\}\) is the event that card 1 is placed in box 1. Since our sample space consists of the placements of each of the cards, each event must be expressed in terms of these outcomes. \item \(\{I_3=1\}=\{1234, 1432, 2134, 2431, 4132, 4231\}\) is the event that card 3 is placed in box 3. Since our sample space consists of the placements of each of the cards, each event must be expressed in terms of these outcomes. \item \(Y=I_1+I_2+I_3+I_4\). \(Y\) represents the total count of matches. The sum \(I_1+I_2+I_3+I_4\) starts with the first box and adds 1 to the count if there is a match (and 0 otherwise), and continues for each of the boxes, resulting in the total count of matches. For example, \(Y(1243) = 2 = 1 + 1 + 0 + 0 = I_1(1243)+I_2(1243)+I_3(1243)+I_4(1243)\). Notice that all the random variables are defined on the same probability space; that is, they have the same inputs. We expand on this idea further in the next subsection. \end{enumerate} Random variables that only take two possible values, 0 and 1, (like \(I_1\) in the previous example) have a special name. \begin{definition} \protect\hypertarget{def:indicator}{}{\label{def:indicator} }An \textbf{indicator (a.k.a.~Bernoulli)} RV can take only the values 0 or 1. If \(A\) is an event then the indicator RV \(\ind_A\) is defined as \[ \ind_A(\omega) = \begin{cases} 1, & \omega \in A,\\ 0, & \omega \notin A \end{cases} \] \end{definition} That is, \(\ind_A\) equals 1 if event \(A\) occurs, and \(\ind_A\) equals 0 if event \(A\) does not occur. Indicators provide the bridge between events and random variables. While simple, they can are very useful. For example, representing a count as a sum of indicator RVs as in Exercise \ref{exm:matching-rv} is a very common and useful strategy. \hypertarget{transform}{% \subsection{Transformations of random variables}\label{transform}} \textbf{A function of a random variable is also a random variable.} That is, if \(X\) is a random variable and \(g:\mathbb{R}\mapsto\mathbb{R}\) is a function, then \(Y=g(X)\) is a random variable\footnote{\(Y(\omega) = g(X(\omega))\) so \(Y\) maps \(\Omega\) to \(\mathbb{R}\) via the composition of the functions \(g\) and \(X\); that is, \(Y=g\circ X\)}. For example, suppose a sample space consists of a set of circles of various sizes. If \(X\) is a random variable representing the radius of a circle selected from this sample space, then \(Y = \pi X^2\) is a random variable representing the area of a circle selected from this sample space. Here we can write \(Y=g(X)\) with \(g(u) = \pi u^2\). \textbf{Sums and products, etc., of random variables \emph{defined on the same probability space} are random variables.} That is, if random variables \(X\) and \(Y\) are defined on the same probability space then \(X+Y\), \(X-Y\), \(XY\), and \(X/Y\) are also random variables. Similarly, it is possible to make comparisons such as \(X\ge Y\) for random variables defined on the same probability space. The following example emphasizes what we mean be ``defined on the same probability space''. \begin{example} \protect\hypertarget{exm:dice-add}{}{\label{exm:dice-add} }Roll a four-sided die twice, and record the result of each roll in sequence. For example, the outcome \((3, 1)\) represents a 3 on the first roll and a 1 on the second; this is not the same outcome as \((1, 3)\). Let \(X_1\) be the result of the first roll, and \(X_2\) the result of the second. \end{example} \begin{enumerate} \def\labelenumi{\arabic{enumi}.} \tightlist \item Evaluate \(X_1((3, 1))\) and \(X_2((3,1))\). \item If an outcome is represented by \(\omega=(\omega_1, \omega_2)\) (e.g.~(3, 1)), specify the functions that define the random variables \(X_1\) and \(X_2\). \item Is \(X=X_1 + X_2\) a valid random variable? If so, identify the function that defines it. \item Evaluate \(X((3, 1))\). \end{enumerate} \begin{solution} \iffalse{} {Solution. } \fi{}to Example \ref{exm:dice-add} \end{solution} \begin{enumerate} \def\labelenumi{\arabic{enumi}.} \tightlist \item \(X_1((3, 1))=3\) and \(X_2((3,1))=1\). \item Recall that there is a single sample space corresponding to the pairs of rolls, rather than a separate sample space for each of the individual rolls. Therefore, random variables need to be defined on the sample space corresponding to pairs of rolls. \(X_1((\omega_1, \omega_2))=\omega_1\) and \(X_2((\omega_1, \omega_2))=\omega_2\). That is, \(X_1\) maps an ordered pair to its first coordinate, and \(X_2\) to its second. \item Yes, \(X=X_1 + X_2\) is a valid random variable. For each outcome \((\omega_1, \omega_2)\), \(X\) returns a number: \(X((\omega_1, \omega_2))=X_1((\omega_1, \omega_2)) + X_2((\omega_1, \omega_2))=\omega_1+\omega_2\) \item \(X((3, 1)) = X_1((3, 1))+X_2((3,1))=3+1=4\). \end{enumerate} The above example probably seems like notational overkill. And of course we could have defined \(X\) directly as \(X((\omega_1,\omega_2))=\omega_1+\omega_2\) without the need for \(X_1, X_2\). But we introduced the example to emphasize that it only makes sense to add random variables if they are defined on the same sample space. Remember that adding two random variables involves adding two \emph{functions}, in the way that the function \(g = g_1 + g_2\) is defined by \(g(u) = g_1(u) + g_2(u)\). It only makes sense to add two functions together if they have the same inputs. For example, consider the random variable \(X\) from Example \ref{exm:coin-rv} and the random variable \(Y\) from Example \ref{exm:matching-rv}. It wouldn't make much practical sense to consider \(X+Y\), but it would make no mathematical sense. How would \(X+Y\) even be defined? \(X\) is defined for sequences of coin flips like HHTH, while \(Y\) is defined for the shuffles in the matching problem like 2143. If you attempted to add \(X\) and \(Y\), which outcomes would go together? Would you add \(X(HHTH)\) to \(Y(2143)\)? Why not add \(X(HHTH)\) to \(Y(1234)\)? Again, adding two random variables involves adding two functions, and it doesn't make sense to add those functions if they have different inputs. As a more practical example, if \(X\) represents SAT math score and \(Y\) represents SAT verbal score then we might be interested in the total score \(X+Y\). Requiring \(X\) and \(Y\) to be defined on the same probability space is like requiring the scores to be measured for the same students. For example, Antwan has both a Math score \(X(\text{Antwan})\) and a Verbal score \(Y(\text{Antwan})\), so we can consider the total score \((X+Y)(\text{Antwan}) = X(\text{Antwan})+Y(\text{Antwan})\). (In statistical terms, the variables are measured for the same observational units.) It wouldn't make sense to add SAT Math scores from one set of students to SAT verbal scores for a different set of students; for example \(X(\text{Antwan}) + Y(\text{Maria})\) makes no sense. \begin{example} \protect\hypertarget{exm:mscoin-rv}{}{\label{exm:mscoin-rv} } Flip a fair coin four times and record the results in order, e.g.~HHTT means two heads followed by two tails. Recall that in Section \ref{sim} we considered the \emph{proportion of the flips which immediately follow a H that result in H}. Remember that we do not consider this proportion if no flips follow a H, i.e.~the outcome is either TTTT or TTTH. Let: \begin{itemize} \tightlist \item \(Z\) be the number of flips immediately following H. \item \(Y\) be the number of flips immediately following H that result in H. \item \(X\) be the proportion of flips immediately following H that result in H. \end{itemize} \end{example} \begin{enumerate} \def\labelenumi{\arabic{enumi}.} \tightlist \item Is \(X\) a random variable? How does it relate to \(Y\) and \(Z\)? \item For each of the possible outcomes in the sample space, find the value of \((Z, Y, X)\). \end{enumerate} \begin{solution} \iffalse{} {Solution. } \fi{}to Example \ref{exm:mscoin-rv} \end{solution} \begin{enumerate} \def\labelenumi{\arabic{enumi}.} \tightlist \item Yes, \(X\) is a random variable because it maps each coin flip sequence to the value of proportion of the flips which immediately follow a H that result in H for that sequence; see the table below. Also, \(X=Y/Z\). Technically \(Y\) and \(Z\) are not defined for outcomes TTTT and TTTH, but we're ignoring those sequences for the purposes of investigating the proportion of the flips which immediately follow a H that result in H. \item In the outcomes below, the \textbf{flips which follow head are in bold}. \end{enumerate} \begin{longtable}[]{@{}lrrr@{}} \caption{\label{tab:mscoin} Possible values of (1) \(Z\), the number of flips immediately following H, (2) \(Y\), the number of flips immediately following H that result in H, and (3) \(X\), the proportion of flips immediately following H that result in H, for four flips of a fair coin.}\tabularnewline \toprule Outcome (\(\omega\)) \textbar{} & \(Z\) \textbar{} & \(Y\) \textbar{} & \(X = Y/Z\) \textbar{}\tabularnewline \midrule \endfirsthead \toprule Outcome (\(\omega\)) \textbar{} & \(Z\) \textbar{} & \(Y\) \textbar{} & \(X = Y/Z\) \textbar{}\tabularnewline \midrule \endhead H\textbf{HHH} \textbar{} & 3 \textbar{} & 3 \textbar{} & 1 \textbar{}\tabularnewline H\textbf{HHT} \textbar{} & 3 \textbar{} & 2 \textbar{} & 2/3 \textbar{}\tabularnewline H\textbf{HT}H \textbar{} & 2 \textbar{} & 1 \textbar{} & 1/2 \textbar{}\tabularnewline H\textbf{T}H\textbf{H} \textbar{} & 2 \textbar{} & 1 \textbar{} & 1/2 \textbar{}\tabularnewline TH\textbf{HH} \textbar{} & 2 \textbar{} & 2 \textbar{} & 1 \textbar{}\tabularnewline H\textbf{HT}T \textbar{} & 2 \textbar{} & 1 \textbar{} & 1/2 \textbar{}\tabularnewline H\textbf{T}H\textbf{T} \textbar{} & 2 \textbar{} & 0 \textbar{} & 0 \textbar{}\tabularnewline H\textbf{T}TH \textbar{} & 1 \textbar{} & 0 \textbar{} & 0 \textbar{}\tabularnewline TH\textbf{HT} \textbar{} & 2 \textbar{} & 1 \textbar{} & 1/2 \textbar{}\tabularnewline TH\textbf{T}H \textbar{} & 1 \textbar{} & 0 \textbar{} & 0 \textbar{}\tabularnewline TTH\textbf{H} \textbar{} & 1 \textbar{} & 1 \textbar{} & 1 \textbar{}\tabularnewline H\textbf{T}TT \textbar{} & 1 \textbar{} & 0 \textbar{} & 0 \textbar{}\tabularnewline TH\textbf{T}T \textbar{} & 1 \textbar{} & 0 \textbar{} & 0 \textbar{}\tabularnewline TTH\textbf{T} \textbar{} & 1 \textbar{} & 0 \textbar{} & 0 \textbar{}\tabularnewline TTTH \textbar{} & 0 \textbar{} & not defined \textbar{} & not defined \textbar{}\tabularnewline TTTT \textbar{} & 0 \textbar{} & not defined \textbar{} & not defined \textbar{}\tabularnewline \bottomrule \end{longtable} \hypertarget{probspace}{% \section{Probability spaces}\label{probspace}} In the previous sections we defined outcomes, events, and random variables, the main mathematical objects associated with a random phenomenon. But we haven't actually computed any probabilities yet. As we saw in Section \ref{consistency}, there are some basic logical consistency requirements that probabilities must satisfy. These requirements are formalized in the following. \begin{definition} \protect\hypertarget{def:probspace}{}{\label{def:probspace} }A \textbf{probability space} is a triple \((\Omega, \mathcal{F}, \IP)\) where \begin{itemize} \tightlist \item \(\Omega\) is a sample space of outcomes \item \(\mathcal{F}\) is a collection of events of interest\footnote{Technically, \(\mathcal{F}\) is a \emph{\(\sigma\)-field} of subsets of \(\Omega\): \(\mathcal{F}\) contains \(\Omega\) and is closed under countably many elementary set operations (complements, unions, intersections). While this level of technical detail is not needed, we prefer to refer to a probability space as a triple to emphasize that probabilities are assigned directly to \emph{events} rather than just outcomes.} \(A\subseteq\Omega\) \item \(\IP\) is a \textbf{probability measure} which assigns a probability \(\IP(A)\) to events \(A\in\mathcal{F}\). A probability measure satisfies the following three axioms \begin{itemize} \tightlist \item \(\IP(\Omega)=1\) \item For all events \(A\in\mathcal{F}\), \(0\le \IP(A)\le 1\) \item (\emph{Countable additivity}.) If events \(A_1, A_2, \ldots\in\mathcal{F}\) are \emph{disjoint (a.k.a. mutually exclusive)} --- that is \(A_i\cap A_j = \emptyset\) for all \(i\neq j\) --- then \begin{equation*} \IP\left(\bigcup_{i=1}^\infty A_i\right) = \sum_{i=1}^\infty \IP\left(A_i\right) \end{equation*} \end{itemize} \end{itemize} \end{definition} The requirement \(0\le \IP(A)\le 1\) makes sense in light of the relative frequency interpretation: an event \(A\) can not occur on more than 100\% of repetitions or less than 0\% of repetitions of the random phenomenon. The requirement that \(\IP(\Omega)=1\) just ensures that the sample space accounts for all of the possible outcomes. If outcome \(\omega\) is observed, then event \(A\) occurs if \(\omega\in A\). If \(\IP(\Omega)<1\) then it would be possible to observe outcomes \(\omega\notin \Omega\); but this violates the requirement that \(\Omega\) is the set of all possible outcomes. Basically, \(\IP(\Omega)=1\) says that on any repetition of the random phenomenon, ``something has to happen''. If \(\Omega\) is a countable set, countable addivity and \(\IP(\Omega)=1\) imply that probability of all the outcomes must add up to 1. For example, in Example \ref{exm:worldseries} \(\IP(\Omega)=1\), together with countable additivity, is what requires that the probability that a team other than those four teams win to be 26\%. Countable additivity is best understood through a diagram with areas representing probabilities, as in the figure below which represents two events (yellow / and blue \textbackslash). On the left, there is no ``overlap'' between areas so the total area is the sum of the two pieces; this depicts countable additivity for two disjoint events. On the right, there is overlap between the two areas, so simply adding the two areas ``double counts'' the intersection (green \(\times\)) and does not result in the correct total area. Countable addivity applies to any number of events, as long as there is no ``overlap''. \begin{figure} \includegraphics[width=10.24in]{_graphics/venn-disjoint} \caption{Illustration of countable additivity for two events. The events in the picture on the left are disjoint, but not on the right.}\label{fig:venn-disjoint} \end{figure} In Example \ref{exm:worldseries}, the events \(A\)=``the Astros win the 2019 World Series'' and \(D\)=``the Dodgers win the 2019 World Series'' are disjoint \(A\cap D = \emptyset\); in a single World Series, both teams cannot win. Therefore, the probability of \(A\cup D\), the event that either the Astros or the Dodgers win, must be 46\%. The three axioms of a probability measure are minimal logical consistency requirements that must be satisfied by any probability model. There are also many physical aspects of the random phenomenon or assumptions (e.g. ``fairness'', independence, conditional relationships) that must be considered when determining a reasonable probability measure for a particular situation. Often, \(\IP\) is defined implicitly through modeling assumptions, and probabilities of events follow from the axioms and related properties. Many other properties follow from the axioms. The main ``meat'' of the axioms is countable additivity. Thus, the key to many proofs of probability properties is to write relevant events in terms of disjoint events. \begin{theorem}[Properties of a probability measure.] \protect\hypertarget{thm:prob-properties}{}{\label{thm:prob-properties} \iffalse (Properties of a probability measure.) \fi{} } Complement rule\footnote{Proof: Since \(\Omega = A \cup A^c\) and \(A\) and \(A^c\) are disjoint the axioms imply that \(1=\IP(\Omega) = \IP(A \cup A^c) = \IP(A) + \IP(A^c)\).}. For any event \(A\), \(\IP(A^c) = 1 - \IP(A)\). In particular, since \(\Omega^c=\emptyset\), \(\IP(\emptyset)=0\). Subset rule\footnote{Proof. If \(A \subseteq B\) then \(B = A \cup (B \cap A^c)\). Since \(A\) and \((B \cap A^c)\) are disjoint, \(\IP(B) = \IP(A) + \IP(B \cap A^c) \ge \IP(A)\).}. If \(A \subseteq B\) then \(\IP(A) \le \IP(B)\). General addition rule for two events\footnote{The proof is easiest to see by considering a picture like the one Figure \ref{fig:venn-disjoint} .}. If \(A\) and \(B\) are any two events \begin{align*} \IP(A\cup B) = \IP(A) + \IP(B) - \IP(A \cap B) \end{align*} Law of total probability. If \(B_1,\ldots, B_k\) are disjoint with \(B_1\cup \cdots \cup B_k=\Omega\), then \begin{align*} \IP(A) & = \sum_{i=1}^k \IP(A \cap B_i) \end{align*} \end{theorem} The key to the proofs is to represent relevant events in terms of disjoint events and use countable addivity (and the other axioms). Note: \(A\cup B\) is inclusive so we \emph{do} want to count the possibility of both, \(A\cap B\). The problem with simply adding \(\IP(A)\) and \(\IP(B)\) is that their sum \emph{double counts} \(A \cap B\). We do want to count the outcomes that satisfy both \(A\) and \(B\), but we only want to count them once. Subtracting \(\IP(A \cap B)\) in the general addition rule for two events corrects for the double counting. For example, consider the picture on the right in Figure \ref{fig:venn-disjoint}. Suppose each rectangular cell represents a distinct outcome; there are 16 outcomes in total. Assume the outcomes are equally likely, each with probability \(1/16\). Let \(A\) represent the yellow / event which has probability \(4/16\) and let \(B\) represent the blue \textbackslash{} event which has probability 4/16. Then \(\IP(A\cup B) = 6/16\), since there are 6 outcomes which satisfy either event \(A\) or \(B\) (or both). However, simply adding \(\IP(A)+\IP(B)\) yields \(8/16\) because the two outcomes that satisfy the green event \(A\cap B\) are counted both in \(\IP(A)\) and \(\IP(B)\). So to correct for this double counting, we subtract out \(\IP(A\cap B)\): \[ \IP(A)+\IP(B)-\IP(A\cap B) = 4/16 + 4/16 -2/16 = 6/16 = \IP(A\cup B) \] Warning: The general addition rule for more than two events is more complicated\footnote{For three events, \(\IP(A\cup B\cup C) = \IP(A) + \IP(B) + \IP(C) - \IP(A\cap B) - \IP(A \cap C) - \IP(B \cap C) + \IP(A \cap B \cap C)\).}; see \href{https://en.wikipedia.org/wiki/Inclusion\%E2\%80\%93exclusion_principle\#In_probability}{the inclusion-exclusion principle}. In the law of total probability\footnote{We will see a different expression of the law of total probability, involving conditional probabilities, in Section \ref{lawtotalprob}.} the events \(B_1, \ldots, B_k\), which represent ``cases'', form a \emph{partition} of the sample space; each outcome \(\omega\in\Omega\) lies in exactly one of the \(B_i\). The law of total probability says that we can interpret the ``overall'' probability \(\IP(A)\) by summing the probability of \(A\) in each ``case'' \(\IP(A\cap B_i)\). \begin{exercise} \protect\hypertarget{exr:linda}{}{\label{exr:linda} }Consider a Cal Poly student who frequently has blurry, bloodshot eyes, generally exhibits slow reaction time, always seems to have the munchies, and disappears at 4:20 each day. Which of the following events, \(A\) or \(B\), has a higher probability? (Assume the two probabilities are not equal.) \begin{itemize} \tightlist \item \(A\): The student has a GPA above 3.0. \item \(B\): The student has a GPA above 3.0 and smokes marijuana regularly. \end{itemize} \end{exercise} \textbf{Warning!} Your psychological judgment of probabilities is often inconsistent with the mathematical logic of probabilities. \begin{example}[Don't do what Donny Don't does.] \protect\hypertarget{exm:dd-notation}{}{\label{exm:dd-notation} \iffalse (Don't do what Donny Don't does.) \fi{} } At various points in his homework, Donny Don't writes the following. Explain to Donny, both mathematically and intuitively, why each of the following symbols is nonsense. Below, \(A\) and \(B\) represent events, \(X\) and \(Y\) represent random variables. \end{example} \begin{enumerate} \def\labelenumi{\arabic{enumi}.} \tightlist \item \(\IP(A = 0.5)\) \item \(\IP(A + B)\) \item \(\IP(A) \cup \IP(B)\) \item \(\IP(X)\) \item \(\IP(X = A)\) \item \(\IP(X \cap Y)\) \end{enumerate} \begin{solution} \iffalse{} {Solution. } \fi{}to Example \ref{exm:dd-notation} \end{solution} \begin{enumerate} \def\labelenumi{\arabic{enumi}.} \tightlist \item \(A\) is a set and 0.5 is a number; it doesn't make mathematical sense to equate them. Suppose that \(A\) is the event that is rains tomorrow. It doesn't make sense to say (as \(A=1\) does) ``it rains tomorrow equals 0.5''. If we want to say ``the probability that it rains tomorrow equals 0.5'' we should write \(\IP(A) = 0.5\). \item \(A\) and \(B\) are sets; it doesn't make mathematical sense to add them. Suppose that \(B\) is the event that tomorrow's high temperature is above 80 degrees F. It doesn't make sense to say (as \(A+B\) does) ``the sum of (it rains tomorrow) and (tomorrow's high temperature is above 80 degrees F)''. If we want ``(it rains tomorrow) OR (tomorrow's high temperature is above 80 degrees F)'', then we need \(A\cup B\). Union is an operation on sets; addition is an operation on numbers. \item \(\IP(A)\) and \(\IP(B)\) are numbers; union is an operation on sets, it doesn't make mathematical sense to take a union of numbers. Since \(\IP(A)\) and \(\IP(B)\) are numbers then mathematically we can add them. But keep in mind that \(\IP(A)+\IP(B)\) is not necessarily a probability, for example if \(\IP(A)=0.5\) and \(\IP(B)=0.6\). If we want ``the probability that (it rains tomorrow) OR (tomorrow's high temperature is above 80 degrees F)'' then the correct symbol is \(\IP(A\cup B)\), which would be equal to \(\IP(A)+\IP(B)\) only if \(A\) and \(B\) were disjoint (which in the example would mean it's not possible to have a rainy day with a high temperature above 80 degrees F). \item \(X\) is a random variable, and probabilities are assigned to events. If \(X\) is tomorrow's high temperature in degrees F then \(P(X)\) reads ``the probability that tomorrow's high temperature in degrees F'', which is missing any qualifying information that could define an event. We could write \(\IP(X>80)\) to represent ``the probability that (tomorrow's high temperature is greater than 80 degrees F)''. \item \(X\) is a random variable (a function) and \(A\) is an event (a set), and it doesn't make sense to equate these two different mathematical objects. It doesn't make sense to say (as \(X=A\) does) ``tomorrow's high temperature in degrees F equals the event that it rains tomorrow''. \item \(X\) and \(Y\) are RVs (functions) and intersection is an operation on sets. If \(Y\) is the amount of rainfall in inches tomorrow then \(X \cap Y\) is attempting to say ``tomorrow's high temperature in degrees F and the amount of rainfall in inches tomorrow'', but this is still missing qualifying information to define a valid event for which a probability can be assigned. We could say \(\IP(\{X > 80\} \cap \{Y < 2\})\) to represent ``the probability that (tomorrow's high temperature is greater than 80 degrees F) AND (the amount of rainfall tomorrow is less than 2 inches)''. \end{enumerate} \hypertarget{probability-measures-in-a-dice-rolling-example}{% \subsection{Probability measures in a dice rolling example}\label{probability-measures-in-a-dice-rolling-example}} A probability measure is a \emph{set function}: \(\IP:\mathcal{F}\mapsto[0, 1]\) takes as an input an event (set) \(A\in\mathcal{F}\) and returns as an output a number \(\IP(A)\in[0,1]\). Sometimes \(\IP(A)\) is defined explicitly for an event \(A\) via a formula. As an example, consider a single roll of a four-sided die. The sample space consists of the four possible outcomes \(\Omega = \{1, 2, 3, 4\}\). Let's first assume that the die is fair, so all four outcomes are equally likely, each with probability\footnote{That the probability of each outcome must be 1/4 when there are four \emph{equally likely} outcomes follows from the axioms, by writing \(\{1, 2, 3, 4\} = \{1\}\cup\{2\}\cup \{3\}\cup \{4\}\), a union of disjoint sets, and applying countable additivity and \(\IP(\Omega)=1\).} 1/4. Given that the probability of each outcome\footnote{A probability measure is always defined on sets. When we say loosely "the probability of an outcome \(\omega\)'\,' we really mean the probability of the event consisting of the single outcome \(\{\omega\}\). In this example \(\IP(\{\omega\})=1/4\) for \(\omega\in\{1, 2, 3, 4\}\)} is 1/4, countable additivity implies \[ \IP(A) = \frac{\text{number of elements in $A$}}{4}, \qquad{\text{$\IP$ assumes a fair four-sided die}} \] The following table lists all the possible events, and their probability under the assumption of equally likely outcomes. \begin{longtable}[]{@{}lll@{}} \caption{\label{tab:die-events-fair} All possible events associated with a single roll of a four-sided die, and their probabilities assuming the die is fair.}\tabularnewline \toprule Event & Description & Probability of event assuming equally likely outcomes\tabularnewline \midrule \endfirsthead \toprule Event & Description & Probability of event assuming equally likely outcomes\tabularnewline \midrule \endhead \(\emptyset\) & Roll nothing (not possible) & 0\tabularnewline \(\{1\}\) & Roll a 1 & 1/4\tabularnewline \(\{2\}\) & Roll a 2 & 1/4\tabularnewline \(\{3\}\) & Roll a 3 & 1/4\tabularnewline \(\{4\}\) & Roll a 4 & 1/4\tabularnewline \(\{1, 2\}\) & Roll a 1 or a 2 & 2/4\tabularnewline \(\{1, 3\}\) & Roll a 1 or a 3 & 2/4\tabularnewline \(\{1, 4\}\) & Roll a 1 or a 4 & 2/4\tabularnewline \(\{2, 3\}\) & Roll a 2 or a 3 & 2/4\tabularnewline \(\{2, 4\}\) & Roll a 2 or a 4 & 2/4\tabularnewline \(\{3, 4\}\) & Roll a 3 or a 4 & 2/4\tabularnewline \(\{1, 2, 3\}\) & Roll a 1, 2, or 3 (a.k.a. do not roll a 4) & 3/4\tabularnewline \(\{1, 2, 4\}\) & Roll a 1, 2, or 4 (a.k.a. do not roll a 3) & 3/4\tabularnewline \(\{1, 3, 4\}\) & Roll a 1, 3, or 4 (a.k.a. do not roll a 2) & 3/4\tabularnewline \(\{2, 3, 4\}\) & Roll a 2, 3, or 4 (a.k.a. do not roll a 1) & 3/4\tabularnewline \(\{1, 2, 3, 4\}\) & Roll something & 1\tabularnewline \bottomrule \end{longtable} The above assignment satsifies all the axioms and so it represents a valid probability measure. But assuming that the outcomes are equally likely requires much more than the basic logical consistency requirements of the axioms. There are many other possible probability measures, like in the following. \begin{example} \protect\hypertarget{exm:die-weighted}{}{\label{exm:die-weighted} }Now consider a single roll of a four-sided die, but suppose the die is weighted so that the outcomes are no longer equally likely (but each outcome is still possible). Suppose that the probability of event \(\{2, 3\}\) is 0.5, of event \(\{3, 4\}\) is 0.7, and of event \(\{1, 2, 3\}\) is 0.6. Complete a table, like the one for the equally likely outcome scenario above, listing the probability of each event for this particular weighted die. In what particular way is the die weighted? That is, what is the probability of each the four possible outcomes? \end{example} \begin{solution} \iffalse{} {Solution. } \fi{}to Example \ref{exm:die-weighted} \end{solution} Since the probability of not rolling a 4 is 0.6, the probability of rolling a 4 must be 0.4. Since \(\{3, 4\} = \{3\} \cup \{4\}\), a union of disjoint sets, the probability of rolling a 3 must be 0.3. Similarly, the probability of rolling a 2 must be 0.2, and the probability of rolling a 1 must be 0.1. The table below list the probabilities of the possible events for this particular weighted die. \begin{longtable}[]{@{}lll@{}} \caption{\label{tab:die-events-weighted} All possible events associated with a single roll of a fair-sided die, and their probabilities assuming the die is weighted: roll a 1 with probability 1/10, 2 with probability 2/10, 3 with probability 3/10, 4 with probability 4/10.}\tabularnewline \toprule Event & Description & Probability of event assuming a particular weighted die\tabularnewline \midrule \endfirsthead \toprule Event & Description & Probability of event assuming a particular weighted die\tabularnewline \midrule \endhead \(\emptyset\) & Roll nothing (not possible) & 0\tabularnewline \(\{1\}\) & Roll a 1 & 0.1\tabularnewline \(\{2\}\) & Roll a 2 & 0.2\tabularnewline \(\{3\}\) & Roll a 3 & 0.3\tabularnewline \(\{4\}\) & Roll a 4 & 0.4\tabularnewline \(\{1, 2\}\) & Roll a 1 or a 2 & 0.3\tabularnewline \(\{1, 3\}\) & Roll a 1 or a 3 & 0.4\tabularnewline \(\{1, 4\}\) & Roll a 1 or a 4 & 0.5\tabularnewline \(\{2, 3\}\) & Roll a 2 or a 3 & 0.5\tabularnewline \(\{2, 4\}\) & Roll a 2 or a 4 & 0.6\tabularnewline \(\{3, 4\}\) & Roll a 3 or a 4 & 0.7\tabularnewline \(\{1, 2, 3\}\) & Roll a 1, 2, or 3 (a.k.a. do not roll a 4) & 0.6\tabularnewline \(\{1, 2, 4\}\) & Roll a 1, 2, or 4 (a.k.a. do not roll a 3) & 0.7\tabularnewline \(\{1, 3, 4\}\) & Roll a 1, 3, or 4 (a.k.a. do not roll a 2) & 0.8\tabularnewline \(\{2, 3, 4\}\) & Roll a 2, 3, or 4 (a.k.a. do not roll a 1) & 0.9\tabularnewline \(\{1, 2, 3, 4\}\) & Roll something & 1\tabularnewline \bottomrule \end{longtable} The symbol \(\IP\) is more than just shorthand for the word ``probability''. \(\IP\) denotes the underlying probability measure, which represents all the assumptions about the probability model. Changing assumptions results in a change of the probability measure. We often consider several probability measures for the same sample space and collection of events; these several measures represent different sets of assumptions and different probability models. In the dice example above, suppose \(\IP\) represents the probability measure corresponding to the assumption of a fair die (equally likely outcomes). With this measure \(\IP(A) = 2/4\) for \(A = \{1, 2\}\). Now let \(\IQ\) represent the probability measure corresponding to the assumption of the weighted die; then \(\IQ(A) = 0.3\). The outcomes and events are the same in both scenarios, because both scenarios involve a four sided-die. What is different is the probability measure that assigns probabilities to the events. One scenario assumes the die is fair while the other assumes the die has a particular weighting, resulting in two different probability measures. Both probability measures in the dice example could be written as explicit set functions: for an event \(A\) \begin{align*} \IP(A) & = \frac{\text{number of elements in $A$}}{4}, & & {\text{$\IP$ assumes a fair four-sided die}} \\ \IQ(A) & = \frac{\text{sum of elements in $A$}}{10}, & & {\text{$\IQ$ assumes a particular weighted four-sided die}} \end{align*} We provide the above descriptions to illustrate that a probability measure operates on sets. However, in many situations there does not exist a simple closed form expression for the set function defining the probability measure which maps events to probabilities. Perhaps the concept of multiple potential probability measures is easier to understand in a subjective probability situation. For example, each model that is used to forecast the 2019 NFL season corresponds to a probability measure which assigns probabilities to events like ``the Eagles win the 2019 Superbowl''. Different sets of assumptions and models can assign different probabilities for the same events. \begin{itemize} \tightlist \item A single probability measure corresponds to a particular set of assumptions about the random phenomenon. \item There can be many probability measures defined on a single sample space, each one corresponding to a different probabilistic model. \item Probabilities of events can change if the probability measure changes. \end{itemize} \hypertarget{uniform-probability-measures-sec-uniform-prob}{% \subsection{Uniform probability measures \#\{sec-uniform-prob\}}\label{uniform-probability-measures-sec-uniform-prob}} Sometimes \(\IP(A)\) is defined explicitly for an event \(A\) via a formula. For example, in the case of a finite sample space with \textbf{equally likely outcomes}, \[ \IP(A) = \frac{|A|}{|\Omega|} = \frac{\text{number of outcomes in $A$}}{\text{number of outcomes in $\Omega$}} \qquad{\text{when outcomes are equally likely}} \] \begin{example} \protect\hypertarget{exm:coin-probspace}{}{\label{exm:coin-probspace} } Flip a coin 4 times, and record the result of each trial in sequence. For example, HTTH means heads on the first on last trial and tails on the second and third. The sample space consists of 16 possible outcomes. One choice of probability measure \(\IP\) corresponds to assuming the 16 possible outcomes are equally likely. (This assumes that the coin is fair and the flips are independent.) \end{example} \begin{enumerate} \def\labelenumi{\arabic{enumi}.} \tightlist \item Specify the probability of each individual outcome, e.g.~\(\{HHTH\}\).\\ \item Find \(\IP(A)\), where \(A\) is the event that exactly 3 of the flips land on heads. \item Find \(\IP(B)\), where \(B\) is the event that exactly 4 of the flips land on heads. \item Find and interpret \(\IP(A \cup B)\). \item Find \(\IP(E_1)\), the event that the first flip results in heads. \item Find \(\IP(E_2)\), the event that the second flip results in heads. \item Find and interpret \(\IP(E_1 \cup E_2)\). \item We assumed the 16 outcomes are equally likely. Do the axioms require this assumption? \end{enumerate} \begin{solution} \iffalse{} {Solution. } \fi{} to Example \ref{exm:coin-probspace} \end{solution} \begin{enumerate} \def\labelenumi{\arabic{enumi}.} \tightlist \item The sample space is composed of 16 outcomes which are assumed to be equally likely, so the probability of each outcome is 1/16. \item \(A = \{HHHT, HHTH, HTHH, THHH\}\) is the event that exactly 3 of the flips land on heads. Since \(A\) consists of 4 distinct equally likely outcomes, \(\IP(A) = 4/16\). \item \(B = \{HHHH\}\), av event consisting of a single outcome, so \(\IP(B) = 1/16\). \item Directly, \(A \cup B = \{HHHT, HHTH, HTHH, THHH, HHHH\}\), so \(\IP(A\cup B) = 5/16\). Also \(A\) and \(B\) are disjoint, so \(\IP(A \cup B) = \IP(A) + \IP(B) = 4/16 + 1/16 = 5/16\). \item Intuitively this is 1/2, but sample space outcomes consist of a sequence of four coin flips, so we should define the proper event. \[ E_1 = \{HHHH, HHHT, HHTH, HTHH, HHTT, HTHT, HTTH, HTTT\} \] So \(\IP(E_1) = 8/16 = 1/2\). \item Similar to the previous part. \[ E_2 = \{HHHH, HHHT, HHTH, THHH, HHTT, THHT, THTH, THTT\} \] So \(\IP(E_2) = 8/16 = 1/2\). \item \(E_1 \cup E_2\) is the event that at least one of the first two flips is heads: \begin{align*} E_1 \cup E_2 & = \{HHHH, HHHT, HHTH, HTHH, THHH, HHTT, \\ & \quad HTHT, HTTH, THHT, THTH, HTTT, THTT\} \end{align*} So \(\IP(E_1 \cup E_2) = 12/16\). Note that \(\E_1\) and \(\E_2\) are not disjoint, so we cannot just add their probabilities. But we can use the general addition rule for two events. \[ E_1 \cap E_2 = \{HHHH, HHHT, HHTH, HHTT\} \] So \(\IP(E_1 \cup E_2) = \IP(E_1) + \IP(E_2) - \IP(E_1 \cap E_2) = 8/16 + 8/16 - 4/16 = 12/16\). \item No, the axioms do not require equally likely outcomes. If, for example, the coin were biased in favor of landing on Heads, we would want a different probability measure. \end{enumerate} Probabilities are always defined for events (sets) but to shorten notation, it is common to write \(\IP(X=3)\) instead of \(\IP(\{X=3\})\), and \(\IP(X = 4, Y = 3)\) instead of \(\IP(\{X = 4\}\cap \{Y = 3\})\). But keep in mind that an expression like ``\(X=3\)'' really represents an event \(\{X=3\}\), an expression which itself represents \(\{\omega\in\Omega: X(\omega) = 3\}\), a subset of \(\Omega\). Probabilities involving multiple events, such as \(\IP(A \cap B)\) or \(\IP(X=4, Y=3)\), are often called \textbf{joint probabilities}. \begin{example} \protect\hypertarget{exm:dice-probspace}{}{\label{exm:dice-probspace} } Roll a four-sided die twice, and record the result of each roll in sequence. For example, the outcome \((3, 1)\) represents a 3 on the first roll and a 1 on the second; this is not the same outcome as \((1, 3)\). One choice of probability measure corresponds to assuming that the die is fair and that the 16 possible outcomes are equally likely. Let \(X\) be the sum of the two dice, and let \(Y\) be the larger of the two rolls (or the common value if both rolls are the same). \end{example} \begin{enumerate} \def\labelenumi{\arabic{enumi}.} \tightlist \item Find the probability of each individual outcome, e.g., \(\{(3, 1)\}\). \item Find \(\IP(A)\) where \(A\) is the event the the sum of the dice is 4. \item Find \(\IP(B)\) where \(B\) is the event the the sum of the dice is at most 3. \item Find \(\IP(\{Y = 3\})\) a.k.a. \(\IP(Y=3)\). \item Find \(\IP(\{Y \le 3\})\) a.k.a. \(\IP( Y\le 3)\). \item Find \(\IP(\{X = 4\}\cap \{Y = 3\})\) a.k.a. \(\IP(X=4, Y=3)\) a.k.a. \(\IP(\{(X,Y) = (4,3)\})\). \item Are the values of \(X\) equally likely? The values of \(Y\)? The values of \((X, Y)\)? \end{enumerate} \begin{solution} \iffalse{} {Solution. } \fi{} to Example \ref{exm:dice-probspace} \end{solution} \begin{enumerate} \def\labelenumi{\arabic{enumi}.} \tightlist \item Since 16 distinct, equally likely outcomes comprise the total probability of 1, the probability of each individual outcome must be 1/16. \item The event that the sum of the dice is 4 is \(A = \{(1, 3), (2, 2), (3, 1)\}\) which can be written as a union of three disjoint sets \(A = \{(1, 3)\} \cup \{(2, 2)\} \cup \{(3, 1)\}\). Therefore, \(\IP(A) = \IP(\{(1, 3)\}) + \IP(\{(2, 2)\}) + \IP(\{(3, 1)\}) = 1/16 + 1/16 + 1/16 = 3/16 = 0.1875\). \item The event the the sum of the dice is at most 3 is \(B=\{(1, 1), (1, 2), (2, 1)\}\), and so similarly to the previous part, \(\IP(B) = 3/16=0.1875\). \item Remember that \(\{Y=3\}\) represents the event that that larger of the two rolls is 3, \(\{Y=3\}=\{(1, 3), (2, 3), (3, 3), (3, 1), (3, 2)\}\), an event which can be written as the union of 5 disjoint events each having probability 1/16. Then \(\IP(\{Y = 3\}) = 5/16=0.3125\). \item \(\{Y \le 3\}=\{(1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3), (3, 1), (3, 2), (3, 3)\}\) so similar to the previous parts \(\IP(Y \le 3) = 9/16=0.5625\). \item \(\{X = 4\}\cap \{Y = 3\} = \{(3, 1), (1, 3)\}\) so \(\IP(\{X = 4\}\cap \{Y = 3\})= 2/16 = 0.125\) \item The values of \(X\) are not equally likely; for example, \(\IP(\{X=4\}) = 3/16\) but \(\IP(\{X=2\})=\IP\{(1, 1)\} = 1/16\). The values of \(Y\) are also not equally likely; for example, \(\IP(\{Y=3\})=5/16\) but \(\IP(\{Y=1\})= \IP\{(1, 1)\} = 1/16\). And the values of \((X, Y)\) pairs are also not equally likely; for example, \(\IP(\{(X, Y) = (4, 3)\}) = 2/16\) but \(\IP(\{(X,Y) = (1, 1)\}) = 1/16\). So just because the underlying outcomes of the sample space are equally likely does not necessarily imply that everything of interest is equally likely as well. \end{enumerate} \begin{example}[Matching problem] \protect\hypertarget{exm:matching-probspace}{}{\label{exm:matching-probspace} \iffalse (Matching problem) \fi{} }Recall the ``matching problem''. A set of \(n\) cards labeled \(1, 2, \ldots, n\) are placed in \(n\) boxes labeled \(1, 2, \ldots, n\), with exactly one card in each box. Consider the case \(n=4\). Let \(Y\) be the number of cards (out of 4) which match the number of the box in which they are placed. We can consider as the sample space the possible ways in which the cards can be distributed to the four boxes. For example, 3214 represents that card 3 is returned (wrongly) to the first box, card 2 is returned (correctly) to the second box, etc. So the sample space consists of the following 24 outcomes\footnote{There are 4 cards that could potentially go in box 1, then 3 cards that could potentially go in box 2, 2 in box 3, and 1 left for box 4. This results in \(4\times3\times2\times1=4! = 24\) possible outcomes.}, which we will assume are equally likely. \begin{center}\rule{0.5\linewidth}{0.5pt}\end{center} \begin{verbatim} 1234 1243 1324 1342 1423 1432 2134 2143 2314 2341 2413 2431 3124 3142 3214 3241 3412 3421 4123 4132 4213 4231 4312 4321 \end{verbatim} \begin{center}\rule{0.5\linewidth}{0.5pt}\end{center} \end{example} \begin{enumerate} \def\labelenumi{\arabic{enumi}.} \tightlist \item What are the possible values of \(Y\)? Find \(\IP(Y=y)\) for each possible value of \(y\). \item Let \(B\) be the event that at least one card is placed in the correct box. Find \(\IP(B)\). \item Let \(B_1\) be the event that card 1 is placed in box 1, and define \(B_2, B_3, B_4\) similarly. Represent the event \(B\) in terms of \(B_1, B_2, B_3, B_4\). \item Find \(\IP(B_1)\). Also find \(\IP(B_2)\), \(\IP(B_3)\), \(\IP(B_4)\). \item Find \(\IP(B_1\cap B_2 \cap B_3 \cap B_4)\). \item Is it possible to compute \(\IP(B_1 \cup B_2 \cup B_3 \cup B_4)\) based on just the five probabilities from the previous two parts? \end{enumerate} \begin{solution} \iffalse{} {Solution. } \fi{} to Example \ref{exm:matching-probspace} \end{solution} The following table evaluates \(Y\) for each of the possible outcomes. \begin{center}\rule{0.5\linewidth}{0.5pt}\end{center} \begin{verbatim} Y(1234)=4 Y(1243)=2 Y(1324)=2 Y(1342)=1 Y(1423)=1 Y(1432)=2 Y(2134)=2 Y(2143)=0 Y(2314)=1 Y(2341)=0 Y(2413)=0 Y(2431)=1 Y(3124)=1 Y(3142)=0 Y(3214)=2 Y(3241)=1 Y(3412)=0 Y(3421)=0 Y(4123)=0 Y(4132)=1 Y(4213)=1 Y(4231)=2 Y(4312)=0 Y(4321)=0 \end{verbatim} \begin{center}\rule{0.5\linewidth}{0.5pt}\end{center} \begin{enumerate} \def\labelenumi{\arabic{enumi}.} \tightlist \item The possible values of \(Y\) are 0, 1, 2, 4. \(Y\) cannot be 3, since if 3 cards match, then the fourth card must necessarily match too. \(\IP(Y=0)=9/24\), \(\IP(Y=1)=8/24\), \(\IP(Y=2)=6/24\), \(\IP(Y=4)=1/24\). \item \(\IP(B) = \IP(Y\ge 1) = 1 - \IP(Y=0) = 15/24 = 0.625\). \item \(B = B_1\cup B_2\cup B_3\cup B_4\). \item Intuitively, \(\IP(B_1)=1/4\) since card 1 is equally likely to be placed in any of the 4 boxes. In terms of the sample space outcomes, \(B_1 =\{1234, 1234, 1243, 1324, 1342, 1423, 1432\}\), so \(\IP(B_1)=6/24=1/4\). Also \(\IP(B_2)=\IP(B_3)=\IP(B_4)=6/24\). \item \(\IP(B_1\cap B_2 \cap B_3 \cap B_4) = \IP({1234}) = 1/24\). \item Nope. The events are not disjoint, so you can't just add their probabilities. Also note that \(\IP(B_1\cup B_2 \cup B_3\cup B_4)\neq \IP(B_1)+\IP(B_2)+\IP(B_3)+\IP(B_4)-\IP(B_1\cap B_2 \cap B_3 \cap B_4)\). As we mentioned previously, the general addition rule is complicated for more than two events. \end{enumerate} For finite sample spaces with equally likely outcomes, computing the probability of an event reduces to counting the number of outcomes that satisfy the event. The continuous analog of equally likely outcomes is a \textbf{uniform probability measure}. When the sample space is uncountable, size is measured continuously (length, area, volume) rather that discretely (counting). \[ \IP(A) = \frac{|A|}{|\Omega|} = \frac{\text{size of } A}{\text{size of } \Omega} \qquad \text{for a uniform probability measure $\IP$} \] \begin{example} \protect\hypertarget{exm:uniform-probspace}{}{\label{exm:uniform-probspace} } Suppose the spinner in Figure \ref{fig:uniform-spinner} is spun twice. Let the sample space be \(\Omega = [0,1]\times [0,1]\) and let \(\IP\) be the uniform probability measure. Find the probability of each of the following events. (Hint: recall that these events are depicted in Figure \ref{fig:uniform-event-plot}) \end{example} \begin{enumerate} \def\labelenumi{\arabic{enumi}.} \tightlist \item \(A\), the event that the first spin is larger then the second. \item \(B\), the event that the smaller of the two spins (or common value if a tie) is less than 0.5. \item \(C\), the event that the sum of the two dice is less than 1.5. \item \(D\), the event that the first spin is less than 0.4. \end{enumerate} \begin{solution} \iffalse{} {Solution. } \fi{} to Example \ref{exm:uniform-probspace} \end{solution} \begin{enumerate} \def\labelenumi{\arabic{enumi}.} \tightlist \item \(\IP(A) = 0.5\). The shaded triangle makes up half the area of the square. This should make sense because the first spin should be equally likely to be the larger of the two spins.\\ \item \(\IP(B) = 0.75\). \item \(\IP(C)=0.875\). The unshaded triangle, representing \(C^c\), has area \((1/2)(0.5)(0.5) = 0.125\). \item \(\IP(D) = 0.4.\) \end{enumerate} ADD plots of shaded rectangles \hypertarget{non-uniform-probability-measures}{% \subsection{Non-uniform probability measures}\label{non-uniform-probability-measures}} For countable sample spaces, the probability measure is often defined by specifying the probability of each individual outcome. Then the probability of an event is obtained by summing the probabilities of the outcomes which comprise the event. Such was the case in Example \ref{exm:die-weighted}; we could have specified the probability measuring by providing the probability of each face (1 with probability 0.1, \ldots, 4 with probability 0.4) and then obtained probabilities of all the events in Table \ref{tab:die-events-weighted} by adding the appropriate outcome probabilities. For uncountable sample spaces, integration typically plays the analogous role that summation plays for countable sample spaces. \begin{example} \protect\hypertarget{exm:exponential-probspace}{}{\label{exm:exponential-probspace} }Consider the sample space \(\Omega=[0,\infty)\) with a probability measure\footnote{This defines the Exponential(1) distribution; see Section \ref{exponential}.} defined by \[ \IP(A) = \int_A e^{-u}\, du, \qquad A \subseteq [0, \infty). \] \end{example} \begin{enumerate} \def\labelenumi{\arabic{enumi}.} \tightlist \item Verify that \(\IP(\Omega)=1\). \item Compute \(\IP(A)\) for \(A=[0, 1]\). \item Without integrating again, compute \(\IP(B)\) for \(B=(1, \infty)\). \item Compute \(\IP(C)\) for \(C=[0, 1] \cup (2, 4)\). \end{enumerate} \begin{solution} \iffalse{} {Solution. } \fi{}to Example \ref{exm:exponential-probspace} \end{solution} \bibliography{book.bib,packages.bib} \end{document}
\input{../../../docs/template_technical} \begin{document} %PART AND CHAPTER DETAILS \renewcommand{\currentpart}{LASA Robotics Technical Documentation for RobotC} \renewcommand{\currentchapter}{Code Normalization using Notepad++} \createtitle{../../../assets} \section{Code Specs} When coding, use these settings in your text editor.\\\\ \indent Indentation: 4 spaces\\ \indent Max line length: 83 characters wide\\ \\These settings are automagically set by the Autofix macro when using Notepad++. \section{What is Notepad++?} Notepad++, also known as npp, is a powerful text file editor. \section{Installing Notepad++} If you already have Notepad++, you can skip this step.\\ Otherwise, download Notepad++ from \url{http://notepad-plus-plus.org}. \section{Installing Autofix Macro} The autofix macro automatically converts any text file's line endings to UNIX format and forces the text file to convert all tabs to spaces, allowing Git to parse without problems. The macro launches with \code{Ctrl+Alt+Shift+S} and automatically saves the current file.\\\\ To install, copy the \code{shortcuts.xml} file to \code{C:/Users/USERNAME/AppData/Roaming/Notepad++/shortcuts.xml} and overwrite. If you have custom macros already, you can edit your \code{shortcuts.xml} to include\\ \code{<Macro name="Autofix" ...} from the LASA Robotics version located in this directory. \end{document}
\filetitle{addparam}{Add model parameters to a database (struct)}{model/addparam} \paragraph{Syntax}\label{syntax} \begin{verbatim} D = addparam(M,D) \end{verbatim} \paragraph{Input arguments}\label{input-arguments} \begin{itemize} \item \texttt{M} {[} model {]} - Model object whose parameters will be added to database (struct) \texttt{D}. \item \texttt{D} {[} struct {]} - Database to which the model parameters will be added. \end{itemize} \paragraph{Output arguments}\label{output-arguments} \begin{itemize} \itemsep1pt\parskip0pt\parsep0pt \item `D {[} struct {]} - Database with the model parameters added. \end{itemize} \paragraph{Description}\label{description} If there are database entries in \texttt{D} whose names conincide with the model parameters, they will be overwritten. \paragraph{Example}\label{example} \begin{verbatim} D = struct(); D = addparam(M,D); \end{verbatim}
\section{The Real and Complex Number Systems} \subsection{Exercise 1} If $rx = q$ or $r+x = q$ for some rational $q$, then substracting $r$ from $q$ or dividing $q$ by $r$ yields $x$ rational, which is a contradiction. \subsection{Exercise 2} We can first show that $\sqrt{3}$ is irrational by seeing that $\frac{a^2}{b^2} = 3 \implies 3 | a, 3 | b$. Then, since $12 = 3 * 2^2$, we have that $\sqrt{12}$ is irrational as well. \subsection{Exercise 4} If $\alpha > \beta$ then $\alpha$ would be an upper bound as well. \subsection{Exercise 5} $\forall x \in A, \: -x \leq \sup{-A}$ and $\forall \epsilon \in \mathbb{R}, \: \exists x \in A \: | \sup{-A} + \epsilon < -x \leq \sup{-A}$. Negating the last inequality gives $\inf{A} = -\sup{-A}$. \subsection{Exercise 6} (a) Follows from $m = \frac{np}{q}$. (b) Put $r = \frac{m}{n}, \: s = \frac{p}{q}$. Then $b^r b^s = b^{\frac{mq}{nq}} b^{\frac{np}{nq}}$. Pulling out $\frac{1}{nq}$ gives the desired result. (c) $b^r$ is an upper bound since $b > 1$, and if it were not the supremum we could choose $t < r$ such that $b^t > b^r$. This is not possible since again, $b > 1$. (d) Every element in $B(x + y)$ can be expressed as $b^{s + t} = b^s b^t \: s \leq x, \: t \leq y$. If $\sup{B(x+y)} = \alpha < \sup{B(x)}\sup{B(y)}$, then $b^s b^t \leq \alpha \implies B(x) \leq \alpha b^{-t} \implies B(y) \leq \frac{\alpha}{B(x)} \implies B(x) B(y) \leq \alpha$. \subsection{Exercise 7} (a) $b^n - 1 = (b - 1) (b^{n-1} + b^{n-2} + ... + 1) \geq n (b-1)$ since $b > 1$. (b) Plug $b^{\frac{1}{n}}$ into (a). (c) Plug $n > \frac{b_-1}{t-1}$ into (b). (d) Using (c) gives that we can choose $n$ such that $b^{\frac{1}{n}} < y \dot b^{-w} \implies b^{w + \frac{1}{n}} < y$. (e) We can take the reciprocal of (c) and do the same as in (d). (f) If $b^x > y$ we can apply (e) for a contradiction, if $b^x < y$ we can apply (d) for a contradiction. (g) Supremum is unique. \subsection{Exercise 8} Suppose $(0, 1) < (0, 0)$. Then $(0, -1) < (0, 0)$ after multiplying by $(0, 1)$ twice yields a contradiction. Similarly, assuming the opposite yields $(-1, 0) > (0, 0)$. \subsection{Exercise 9} Does exhibit least upper-bound property since you can take $(\sup{a_i}, \sup{b_i})$. \subsection{Exercise 10} Exception is 0. \subsection{Exercise 11} Take $w = \frac{1}{\abs{z}}z$ and $r = \abs{z}$ when $\abs{z} \neq 0$. $w$ and $r$ are not uniquely determined; take $z = 0$ for example. \subsection{Exercise 12} By strong induction: \begin{align*} \abs{z_1 + ... + z_{n+1}} &\leq \abs{z_1 + ... + z_n} + \abs{z_{n+1}} \\ &\leq \abs{z_1} + ... + \abs{z_{n+1}} \end{align*} \subsection{Exercise 13} \begin{align*} \abs{x - y}^2 &= x\bar{x} - 2\abs{x}\abs{y} + y \bar{y} \\ &\geq (\abs{x} - \abs{y})^2 \end{align*}
\subsection{Method Description and Its Implementation} \noindent We will denote the functions space that vanishes at the borders as $H^1_0 (0, 1)$. Setting $A = \alpha \partial^2_{\xi}$ and $B = \frac{1}{2} \partial_{\xi} (x^2)$, $x \in \mathcal{H}$, with its domains $D(A) = H^2 (0, 1) \cap H^1_0 (0, 1)$ and $D(B) = H^1_0 (0, 1)$ respectively, then by (\ref{stochastic_equation}), the equation (\ref{burgers_stochastic2}) can be rewritten as \begin{align*} dX &= [AX + B(X)]dt + dW_t \\ X(0) &= x, \hspace{0.2cm} x \in \mathcal{H} \end{align*} where $A$ have eigenfunctions in $\mathcal{H}$ given by \begin{align*} e_k (\xi) = \sqrt{2} \sin{(k \pi \xi)}, \hspace{3mm} \xi \in [0, 1], \hspace{3mm} k \in \mathbb{N} \end{align*} \noindent Note that the operator $A$ satisfies $Ae_k = -\alpha \pi^2 k^2 e_k$ for $k \in \mathbb{N}$, then if we set $\Lambda = (-A)^{-1}$ we have that $\Lambda^{-1/2} e_k = \sqrt{2 \alpha} \pi |k| e_k$. \\ Therefore, as in (\ref{infinite_system}) we need to solve the following system \begin{align} \dot{u}_{m} (t) = -u_{m} (t) \lambda_{m} + \displaystyle \sum _{n \in \mathcal{J}} u_{n} (t) C_{n, m} , \hspace{0.1cm} n, m \in \mathcal{J} \end{align} \noindent We need to calculate the value of the constants $C_{n,m}$ , then we need to calculate expressions such as $B(x)$, $D_x H_n (x)$. Note that $x$ can be written as $x = \displaystyle \sum_{k} \beta_k e_k$ , with $\beta_k := \langle x, e_k \rangle_{\mathcal{H}}$. Then we have \begin{align*} B(x) = \frac{1}{2} \partial_{\xi} \left( \displaystyle \sum_k \beta_k e_k \right)^2 = \frac{1}{2} \partial_{\xi} \left[ \sum_l \sum_k \beta_l \beta_k e_l e_k \right] = \frac{1}{2} \sum_l \sum_k \beta_l \beta_k (e_l e'_k + e'_l e_k) \end{align*} and for $D_x H_n (x)$ we have \begin{align*} D_x H_n (x) = \displaystyle \sum_{j = 1}^{\infty} \prod_{i = 1. i \neq j}^{\infty} P_{n_i} (\langle x, \Lambda^{-1 / 2} e_i \rangle_{\mathcal{H}}) P'_{n_j} (\langle x, \Lambda^{-1 / 2} e_j \rangle_{\mathcal{H}}) \Lambda^{-1 / 2} e_j \end{align*} \noindent Therefore, $C_{n, m}$ given by (\ref{Cnm}) gives \begin{align*} C_{n, m} =& \displaystyle \frac{1}{2} \int_{\mathcal{H}} H_m (x) \mu (dx) \sum_{j = 1}^{\infty} \prod_{i = 1, i \neq j}^{\infty} P_{n_i} (\langle x, \Lambda^{-1 / 2} e_i \rangle_{\mathcal{H}}) P'_{n_j} (\langle x, \Lambda^{-1 / 2} e_j \rangle_{\mathcal{H}}) \sqrt{2 \alpha} \pi |j| \\ &\cdot \sum_l \sum_k \beta_l \beta_k (e_l e'_k + e'_l e_k) \\ =& \displaystyle \frac{1}{2} \int_{\mathcal{H}} \mu (dx) \sum_{j = 1}^{\infty} \sqrt{2 \alpha} \pi |j| P_{m_j} (\langle x, \Lambda^{-1 / 2} e_j \rangle_{\mathcal{H}}) P'_{n_j} (\langle x, \Lambda^{-1 / 2} e_j \rangle_{\mathcal{H}}) \\ &\cdot \prod_{i = 1, i \neq j}^{\infty} P_{n_i} (\langle x, \Lambda^{-1 / 2} e_i \rangle_{\mathcal{H}}) P_{m_i} (\langle x, \Lambda^{-1 / 2} e_i \rangle_{\mathcal{H}}) \\ &\cdot \sum_l \sum_k \beta_l \beta_k (e_l e'_k + e'_l e_k) \end{align*} So, to obtain a truncated approximation of the solution, the following set of indices is considered \begin{align} J^{M, N} = \{\gamma = (\gamma_i, \hspace{1mm} 1 \leq \gamma_i \leq M ) \hspace{1mm} | \hspace{1mm} \gamma_i \in \{0, 1, \cdots, N \} \} \end{align} this is the set of $M$-tuple which can take values in the set $\{0, 1, \cdots, N \}$. \\ For $N_1 \in \mathbb{N}$ define as the set $S_{N_1} = \{n_1 , n_2 , \cdots , n_{N_1} : n_i \in J^{M,N} , i = 1, \cdots , N_1 \}$. Then for $n, m \in S_{N}$ we have \begin{align*} \bar{C}_{n, m} =& \displaystyle \frac{1}{2} \sum_{j = 1}^{\infty} \sqrt{2 \alpha} \pi |j| \int_{\mathcal{\mathbb{R}^M}} P_{m_j} (\xi_j) P'_{n_j} (\xi_j) \mu (d \xi_j) \\ &\cdot \prod_{i = 1, i \neq j}^{M} P_{m_i} (\xi_i) P_{n_i} (\xi_i) \mu (d \xi_i) \sum_{l=1}^{M} \sum_{k=1}^{M} \beta_l \beta_k (e_l e'_k + e'_l e_k) \end{align*} and for $m_1, m_2, \cdots, m_M \in J^{M, N}$ the system (\ref{infinite_system}) give us \begin{align} \label{finite_system} \dot{u}_{m_i} (t) = -u_{m_i} (t) \lambda_{m_i} + \displaystyle \sum_{j=1}^{M} u_{n_j} (t) C_{n_j, m_i} , \hspace{2mm} 1 \leq i \leq M \end{align} The solutions of the previous system can be calculated in terms of their eigenvectors by establishing the following vector \begin{equation*} U^M (t) = \begin{pmatrix} u_{m_1} (t) & u_{m_2} (t) & \dots & u_{m_M} (t) \end{pmatrix}^T \end{equation*} and for its derivatives \begin{equation*} \dot{U}^M (t) = \begin{pmatrix} \dot{u}_{m_1} (t) & \dot{u}_{m_2} (t) & \dots & \dot{u}_{m_M} (t) \end{pmatrix}^T \end{equation*} So, we can now write the system (\ref{finite_system}) as \begin{align} \label{finite_system_vectorial} \dot{U}^M (t) = A U^M (t) \end{align} where the matrix $A$ is given by \begin{equation*} A = \begin{pmatrix} -\lambda_1 + C_{1,1} & C_{2,1} & \dots & C_{M-1,1} & C_{M,1} \\ C_{1,2} & -\lambda_2 + C_{2,2} & \dots & C_{M-1,2} & C_{M,2} \\ \vdots & \vdots & \ddots & \vdots & \vdots \\ C_{1,M-1} & C_{2,M-1} & \dots & -\lambda_{M-1} + C_{M-1,M-1} & C_{M,M-1} \\ C_{1,M} & C_{2,M} & \dots & C_{M-1,M} & -\lambda_{M} + C_{M,M} \end{pmatrix} \end{equation*} where $\lambda_i = \lambda_{mi}$ and $C_{i, j} = C_{n_i, m_j}$ para $1 \leq i, j \leq M$. \\ \noindent Then, if $A$ has $M$ real and distint eigenvalues $\eta_i$ and $M$ eigenvectors $V_i$, then the solution to (\ref{finite_system_vectorial}) is given by \begin{align} \label{solution_finite_system} U^M (t) = \displaystyle \sum _{j = 1}^{M} c_i V_i e^{\eta_i t} \end{align} In the case when some eigenvalue is complex, we can write it together with its eigenvector as follows \begin{align*} V &= a + i b, \hspace{3mm} \eta = \beta + i \mu \end{align*} to get the solutions \begin{align*} e^{\beta t} (a \cos(\mu t) - b \sin(\mu t)), \hspace{2mm} e^{\beta t} (a \sin(\mu t) + b \cos(\mu t)) \end{align*} which are real and different. \\ Then we can write the approximation of the solution of (\ref{kolmogorov}) as \begin{align} \label{finite_approximation} u_M (x, t) = \displaystyle \sum_{ n \in J^{M, N} } u_n (t) H_n (x) = U^M (t) H^M (x), \hspace{2mm} x \in \mathcal{H}, \hspace{2mm}, t \in [0, T]. \end{align} Also, if $u (\xi, t) = \mathbb{E} \left [X_t (\xi) \right]$, then satisfies the problem given by \begin{align*} \frac{\partial u}{\partial t} = \alpha \frac{\partial^2 u}{\partial \xi^2} + \partial_{\xi} \left[ u(\xi, t) \right]^2 \end{align*} with the initial condition $u(\xi, 0) = \mathbb{E} \left[ X_0 \right]$.
\documentclass[psamsfonts]{amsart} %-------Packages--------- \usepackage{amsmath,amssymb,amsfonts} \usepackage[all,arc]{xy} \usepackage{enumerate} \usepackage{mathrsfs} %--------Theorem Environments-------- %theoremstyle{plain} --- default \newtheorem{thm}{Theorem}[section] \newtheorem{cor}[thm]{Corollary} \newtheorem{prop}[thm]{Proposition} \newtheorem{lem}[thm]{Lemma} \newtheorem{conj}[thm]{Conjecture} \newtheorem{quest}[thm]{Question} \theoremstyle{definition} \newtheorem{defn}[thm]{Definition} \newtheorem{defns}[thm]{Definitions} \newtheorem{con}[thm]{Construction} \newtheorem{exmp}[thm]{Example} \newtheorem{exmps}[thm]{Examples} \newtheorem{notn}[thm]{Notation} \newtheorem{notns}[thm]{Notations} \newtheorem{addm}[thm]{Addendum} \newtheorem{exer}[thm]{Exercise} \theoremstyle{remark} \newtheorem{rem}[thm]{Remark} \newtheorem{rems}[thm]{Remarks} \newtheorem{warn}[thm]{Warning} \newtheorem{sch}[thm]{Scholium} \makeatletter \let\c@equation\c@thm \makeatother \numberwithin{equation}{section} \bibliographystyle{plain} \DeclareMathOperator{\Tr}{Tr} %--------Meta Data: Fill in your info------ \title{Statistical Analysis of Medical Data} \author{Won I. Lee} %\date{DEADLINES: Draft AUGUST 18 and Final version AUGUST 29, 2013} \begin{document} \maketitle \section{Introduction and Motivation} Due to a myriad of considerations, the realm of medical data remains woefully underexplored by modern methods of statistics and machine learning. There are, of course, many times of biomedical, bioinformatic, genetic, etc. data that have been examined quite extensively in the literature; what interests us in this particular article is medical data recorded by hospitals and physicians for use in practice. Such data may include physiological measurements, notes by physicians, drug intake, surgical outcomes, and more. The most prominent barrier against entry is the understandably major privacy considerations involved with such data. \begin{thebibliography}{9} \bibitem{tsirelson85} B. S. Tsirelson, “Quantum analogs of the Bell inequalities. The case of two spatially separated domains”, J. Math. Sci. 36(3), 557–570 (1987). Translated from Russian: Zapiski LOMI 142, 174-194 (1985). \bibitem{resume} A. Grothendieck, “R´esum´e de la th´eorie m´etrique des produits tensoriels topologiques” (French), Bol. Soc. Mat. Sao Paulo 8, 1–79 (1953). \bibitem{GT} G. Pisier, "Grothendieck's theorem, past and present", arXiv. \end{thebibliography} \end{document}
% Created 2021-03-29 Mon 20:21 % Intended LaTeX compiler: xelatex \documentclass[letterpaper,11pt]{article} %% Margins \usepackage{geometry} \geometry{verbose,margin=1.5in} \setlength\parindent{0pt} \linespread{1.1} %% Typesetting \usepackage[stretch=10,babel=true]{microtype} % better typesetting. works w/ pdftex, not latex. %% \usepackage[english]{babel} % manages hyphenation patterns %% \usepackage{polyglossia} \setdefaultlanguage{english} % babel replacement for XeLaTex. \usepackage{csquotes} % Context sensitive quotation facilities %% Biblio \usepackage[natbib=true, sorting=ynt, backend=biber, minbibnames=3, maxbibnames=3, doi=false, isbn=false, style=authoryear]{biblatex} \addbibresource{~/Zotero/myref.bib} \AtEveryBibitem{\clearfield{note}} \AtEveryBibitem{\clearfield{month}} \AtEveryBibitem{\clearfield{day}} \AtEveryBibitem{\clearfield{eprint}} %% Math \usepackage{amsmath} % \declareMathOperator \usepackage[mathbf=sym]{unicode-math} %% \usepackage{cool} % for math operators & symbols e.g. partial diff \usepackage{mathtools} % for math aligning & spacing \usepackage{physics} % derivative, dx, operators \usepackage{cancel} \allowdisplaybreaks % Allow new page within align %% Font \usepackage{kotex} \setmainfont{XITS} \setmathfont{XITS Math} % \boldsymbol works \setmathfont[range={\mathcal,\mathbfcal},StylisticSet=1]{XITS Math} \usepackage[unicode,colorlinks]{hyperref} \usepackage{graphicx} \usepackage{subfigure} \usepackage{grffile} % Extended file name support for graphics (legacy package) \usepackage{float} % Fix figures and tables by [H] \usepackage{longtable} \usepackage{wrapfig} \usepackage{rotating} \usepackage[normalem]{ulem} \usepackage{textcomp} \usepackage{capt-of} \author{Jonghyun Yun} \date{\today} \title{\textit{[2021-03-29 Mon] } Discussion} \hypersetup{ pdfauthor={Jonghyun Yun}, pdftitle={\textit{[2021-03-29 Mon] } Discussion}, pdfkeywords={}, pdfsubject={}, pdfcreator={Emacs 27.1 (Org mode 9.5)}, pdflang={English}} \begin{document} \maketitle \section*{\textit{[2021-03-29 Mon] } Updates} \label{sec:orgfb91d4a} \begin{itemize} \item Code debugging finished for MCMC sampler (\(\beta, \theta\)) \item \(\beta_{ic}\) is non-identifiable, dropped. \item New posterior analysis is ready to look. \item piecewise approximation segment number: back to 5 (was 2). \begin{itemize} \item at a small \# of segments, the latent space doesn't improve the fit to chessB data (log-loss). \end{itemize} \item 유월 서브미션 목표!! \end{itemize} \section*{Log-loss} \label{sec:org04bec69} Given the survival time \(t\) and MCMC samples, the conditional probability of ``correct'' response is estimated as \[ \hat p_{ik}^{(l)}(t) = \frac{h_{i1}^{(l)}(t)}{h_{i1}^{(l)}(t) + h_{i0}^{(l)}(t)}, \] where \((l)\) denote the index of MCMC sample used to calculate the quantity. We use \(Y_{ik} = 1\) to denote a correct response, and \(Y_{ik} = 0\) an incorrect response. Then, \(p_{ik}^{(l)}(t)\) can be served as the prediction probability of \(Y_{ik}\), which allows using classification performance metrics. For easiness of evaluation, we use the log-loss for item: \[ -\frac{1}{N} \sum_{k} \left\{ y_{ik} \log \hat p_{ik}^{(l)}(t) + (1-y_{ik}) \log (1 - \hat p_{ik}^{(l)})\right\}. \] \section*{Models} \label{sec:org88b34bf} \texttt{double pp} model: the smaller distance, the faster process \begin{align*} h_{i1}(t) &= \lambda_{i1}(t) \exp(\theta_{k1} - \gamma_{1} ||z_{k1} - w_{i1}||) \\ h_{i0}(t) &= \lambda_{i0}(t) \exp(\theta_{k0} - \gamma_{0} ||z_{k0} - w_{i0}||) \\ \end{align*} \texttt{np} model: the smaller distance, the more distinct process (in terms of speed). \begin{align*} h_{i1}(t) &= \lambda_{i1}(t) \exp(\theta_{k1} + \gamma ||z_{k} - w_{i}||) \\ h_{i0}(t) &= \lambda_{i0}(t) \exp(\theta_{k0} - \gamma ||z_{k} - w_{i}||) \\ \end{align*} \section*{\(\gamma\) is non-identifiable, but it's ok to keep} \label{sec:org918211b} \texttt{np} model with \(\gamma = 1\). \begin{align*} h_{i1}(t) &= \lambda_{i1}(t) \exp(\theta_{k1} + ||z_{k} - w_{i}||) \\ h_{i0}(t) &= \lambda_{i0}(t) \exp(\theta_{k0} - ||z_{k} - w_{i}||) \\ \end{align*} \begin{itemize} \item priors on the latent space \begin{align*} \pi\left(\mathbf{z}_{j}\right) & \sim \mathrm{MVN}_{d}\left(0, I_{d}\right) \\ \pi\left(\mathbf{w}_{i}\right) & \sim \mathrm{MVN}_{d}\left(0, I_{d}\right) \\ \end{align*} \item results (latent space structure) heavily depend on the prior variance (\(\sigma_{zw}\)) of \(z_{k}\) and \(w_{i}\). \item we should let the data determine \(\sigma_{zw}\). \end{itemize} \section*{{\bfseries\sffamily KILL} fit the model} \label{sec:orga265a6f} \begin{itemize} \item State ``KILL'' from ``TODO'' \textit{[2021-03-29 Mon 09:29] } \\ cannot do the model selection based on a non-identifiable parameter. \end{itemize} \begin{align*} h_{i1}(t) &= \lambda_{i1}(t) \exp(\theta_{k1} + \gamma_{} ||z_{k} - w_{i}||) \\ h_{i0}(t) &= \lambda_{i0}(t) \exp(\theta_{k0} - \gamma_{} ||z_{k} - w_{i}||) \\ \end{align*} \[ \gamma_{} \sim N(0,1) \] \section*{diffused priors?} \label{sec:org891850c} \begin{align*} \pi\left(\lambda_{ic,j}\right) & \sim \operatorname{Gamma}\left(\text{mean} = \tilde \lambda_{ic,j}, \text{var} = C \cdot \tilde \lambda_{ic,j})\right) \\ \pi\left(\theta_{k} | \sigma^{2}\right) & \sim \mathrm{N}\left(0, \sigma^{2}\right) \\ \pi\left(\sigma^{2}\right) & \sim \operatorname{lnv}-\operatorname{Gamma}\left(a_{\sigma}, b_{\sigma}\right) \\ \pi\left(\mathbf{z}_{j}\right) & \sim \mathrm{MVN}_{d}\left(0, I_{d}\right) \\ \pi\left(\mathbf{w}_{i}\right) & \sim \mathrm{MVN}_{d}\left(0, I_{d}\right) \\ \pi( \log \gamma) & \sim \mathrm{N}\left(\mu_{\gamma}, \tau_{\gamma}^{2}\right) \end{align*} \[C = 2, a_{\sigma}=0.0001, b_{\sigma}=0.0001, \mu_{\gamma}=0, \text { and } \tau_{\gamma}^{}=2\] \subsection*[How to set \(\lambda\) priors]{How to set \(\lambda\) priors\hfill{}\textsc{ATTACH}} \label{sec:org85b5ee2} C=2, K\_j: number of segments, U\_j = 3rd quartile, k: k-th segment. \begin{center} \includegraphics[width=.9\linewidth]{/Users/yunj/org/.attach/ad/c42ad2-5845-4405-bed4-b640f540b3d9/_20210322_183639screenshot.png} \end{center} \section*{New results with unknown \(\gamma > 0\).} \label{sec:org12f4918} baseline model: \begin{align*} h_{i1}(t) &= \lambda_{i1}(t) \exp(\theta_{k1})\\ h_{i0}(t) &= \lambda_{i0}(t) \exp(\theta_{k0})\\ \end{align*} \begin{center} \includegraphics[width=.9\linewidth]{chessB_RTnACC.pdf} \end{center} \begin{center} \begin{tabular}{l} chessB\_no\_latent\_ncut5\_zero\_beta\_noinfo\_lc2\\ chessB\_double\_nn\_ncut5\_zero\_beta\_noinfo\_lc2\\ chessB\_double\_np\_ncut5\_zero\_beta\_noinfo\_lc2\\ chessB\_double\_pn\_ncut5\_zero\_beta\_noinfo\_lc2\\ chessB\_double\_pp\_ncut5\_zero\_beta\_noinfo\_lc2\\ chessB\_nn\_ncut5\_zero\_beta\_noinfo\_lc2\\ chessB\_np\_ncut5\_zero\_beta\_noinfo\_lc2\\ \textbf{chessB\_pn\_ncut5\_zero\_beta\_noinfo\_lc2}\\ chessB\_pp\_ncut5\_zero\_beta\_noinfo\_lc2\\ chessB\_swdz\_nn\_ncut5\_zero\_beta\_noinfo\_lc2\\ chessB\_swdz\_pp\_ncut5\_zero\_beta\_noinfo\_lc2\\ \end{tabular} \end{center} Updated package file: \textbf{art\_0.1.1.tar.gz} \end{document}
\chapter{Command processor} \label{chapter:command-processor} This chapter details Scheme~48's command processor, which incorporates both a read-eval-print loop and an interactive debugger. At the \code{>} prompt, you can type either a Scheme form (expression or definition) or a command beginning with a comma. In \link*{inspection mode}[inspection mode (see section~\Ref)]{inspector} the prompt changes to \code{:} and commands no longer need to be preceded by a comma; input beginning with a letter or digit is assumed to be a command, not an expression. In inspection mode the command processor prints out a menu of selectable components for the current object of interest. \section{Current focus value and {\tt \#\#}} The command processor keeps track of a current {\em focus value}. This value is normally the last value returned by a command. If a command returns multiple values the focus object is a list of the values. The focus value is not changed if a command returns no values or a distinguished `unspecific' value. Examples of forms that return this unspecific value are definitions, uses of \code{set!}, and \code{(if \#f 0)}. It prints as \code{\#\{Unspecific\}}. The reader used by the command processor reads \code{\#\#} as a special expression that evaluates to the current focus object. \begin{example} > (list 'a 'b) '(a b) > (car ##) 'a > (symbol->string ##) "a" > (if #f 0) #\{Unspecific\} > ## "a" > \end{example} \section{Command levels} If an error, keyboard interrupt, or other breakpoint occurs, or the \code{,push} command is used, the command processor invokes a recursive copy of itself, preserving the dynamic state of the program when the breakpoint occured. The recursive invocation creates a new {\em command level}. The command levels form a stack with the current level at the top. The command prompt indicates the number of stopped levels below the current one: \code{>} or \code{:} for the base level and \code{\cvar{n}>} or \code{\cvar{n}:} for all other levels, where \cvar{n} is the command-level nesting depth. The \code{auto-levels} switch described below can be used to disable the automatic pushing of new levels. The command processor's evaluation package and the value of the \code{inspect-focus-value} switch are local to each command level. They are preserved when a new level is pushed and restored when it is discarded. The settings of all other switches are shared by all command levels. \begin{description} \item $\langle{}$eof$\rangle{}$\\ Discards the current command level and resumes running the level down. $\langle{}$eof$\rangle{}$ is usually control-\code{D} at a Unix shell or control-\code{C} control-\code{D} using the Emacs \code{cmuscheme48} library. \item \code{,pop}\\ The same as $\langle{}$eof$\rangle{}$. \item \code{,proceed [\cvar{exp} \ldots}]\\ Proceed after an interrupt or error, resuming the next command level down, delivering the values of \cvar{exp~\ldots} to the continuation. Interrupt continuations discard any returned values. \code{,Pop} and \code{,proceed} have the same effect after an interrupt but behave differently after errors. \code{,Proceed} restarts the erroneous computation from the point where the error occurred (although not all errors are proceedable) while \code{,pop} (and $\langle{}$eof$\rangle{}$) discards it and prompts for a new command. \item \code{,push}\\ Pushes a new command level on above the current one. This is useful if the \code{auto-levels} switch has been used to disable the automatic pushing of new levels for errors and interrupts. \item \code{,level [\cvar{number}]}\\ Pops down to a given level and restarts that level. \cvar{Number} defaults to zero. \item \code{,reset}\\ \code{,reset} restarts the command processor, discarding all existing levels. \end{description} Whenever moving to an existing level, either by sending an $\langle{}$eof$\rangle{}$ or by using \code{,reset} or the other commands listed above, the command processor runs all of the \code{dynamic-wind} ``after'' thunks belonging to stopped computations on the discarded level(s). \section{Logistical commands} \begin{description} \item \code{,load \cvar{filename \ldots}}\\ Loads the named Scheme source file(s). Easier to type than \code{(load "\cvar{filename}")} because you don't have to shift to type the parentheses or quote marks. Also, it works in any package, unlike \code{(load "\cvar{filename}")}, which will work only work in packages in which the variable \code{load} is defined appropriately. \item \code{,exit [\cvar{exp}]} Exits back out to shell (or executive or whatever invoked Scheme~48 in the first place). \cvar{Exp} should evaluate to an integer. The integer is returned to the calling program. The default value of \cvar{exp} is zero, which, on Unix, is generally interpreted as success. \end{description} \section{Module commands} \label{module-command-guide} There are many commands related to modules. Only the most commonly used module commands are described here; documentation for the rest can be found in \link*{the module chapter}[section~\Ref]{module-commands}. There is also \link*{a brief description of modules, structures, and packages} [a brief description of modules, structures, and packages in section~\Ref] {module-guide} below. \begin{description} \item \code{,open \cvar{structure \ldots}}\\ Makes the bindings in the \cvar{structure}s visible in the current package. The packages associated with the \cvar{structure}s will be loaded if this has not already been done (the \code{ask-before-loading} switch can be used disable the automatic loading of packages). \item \code{,config [\cvar{command}]}\\ Executes \cvar{command} in the \code{config} package, which includes the module configuration language. For example, use \begin{example} ,config ,load \cvar{filename} \end{example} to load a file containing module definitions. If no \cvar{command} is given, the \code{config} package becomes the execution package for future commands. \item \code{,user [\cvar{command}]} \\ This is similar to the {\tt ,config}. It moves to or executes a command in the user package (which is the default package when the \hack{} command processor starts). \end{description} \section{Debugging commands} \label{debug-commands} \begin{description} \item \code{,preview}\\ Somewhat like a backtrace, but because of tail recursion you see less than you might in debuggers for some other languages. The stack to display is chosen as follows: \begin{enumerate} \item If the current focus object is a continuation or a thread, then that continuation or thread's stack is displayed. \item Otherwise, if the current command level was initiated because of a breakpoint in the next level down, then the stack at that breakpoint is displayed. \item Otherwise, there is no stack to display and a message is printed to that effect. \end{enumerate} One line is printed out for each continuation on the chosen stack, going from top to bottom. \item \code{,run \cvar{exp}}\\ Evaluate \cvar{exp}, printing the result(s) and making them (or a list of them, if \cvar{exp} returns multiple results) the new focus object. The \code{,run} command is useful when writing \link*{command programs} [command programs, which are described in section~\Ref{} below] {command-programs}. \item \code{,trace \cvar{name} \ldots}\\ Start tracing calls to the named procedure or procedures. With no arguments, displays all procedures currently traced. This affects the binding of \cvar{name}, not the behavior of the procedure that is its current value. \cvar{Name} is redefined to be a procedure that prints a message, calls the original value of \cvar{name}, prints another message, and finally passes along the value(s) returned by the original procedure. \item \code{,untrace \cvar{name} \ldots}\\ Stop tracing calls to the named procedure or procedures. With no argument, stop tracing all calls to all procedures. \item \code{,condition}\\ The \code{,condition} command displays the condition object describing the error or interrupt that initiated the current command level. The condition object becomes the current focus value. This is particularly useful in conjunction with the inspector. For example, if a procedure is passed the wrong number of arguments, do \code{,condition} followed by \code{,inspect} to inspect the procedure and its arguments. \item \code{,bound?\ \cvar{name}}\\ Display the binding of \cvar{name}, if there is one, and otherwise prints `\code{Not bound}'. \item \code{,expand \cvar{form}} \T\vspace{-1em} \item \code{,expand-all \cvar{form}}\\ Show macro expansion of \cvar{form}, if any. \code{,expand} performs a single macro expansion while \code{,expand-all} fully expands all macros in \cvar{form}. \item \code{,where \cvar{procedure}}\\ Display name of file containing \cvar{procedure}'s source code. \end{description} \section{Switches} There are a number of binary switches that control the behavior of the command processor. The switches are as follows: \begin{description} \item \code{batch [on | off]}\\ In `batch mode' any error or interrupt that comes up will cause Scheme~48 to exit immediately with a non-zero exit status. Also, the command processor doesn't print prompts. Batch mode is off by default. % JAR says: disable auto-levels by default?? \item \code{,levels [on | off]}\\ Enables or disables the automatic pushing of a new command level when an error, interrupt, or other breakpoint occurs. When enabled (the default), breakpoints push a new command level, and $\langle{}$eof$\rangle{}$ (see above) or \code{,reset} is required to return to top level. The effects of pushed command levels include: \begin{itemize} \item a longer prompt \item retention of the continuation in effect at the point of errors \item confusion among some newcomers \end{itemize} With \code{levels} disabled one must issue a \code{,push} command immediately following an error in order to retain the error continuation for debugging purposes; otherwise the continuation is lost as soon as the focus object changes. If you don't know anything about the available debugging tools, then levels might as well be disabled. \item \code{break-on-warnings [on | off]}\\ Enter a new command level when a warning is produced, just as when an error occurs. Normally warnings only result in a displayed message and the program does not stop executing. \end{description} \section{Inspection mode} \label{inspector} There is a data inspector available via the \code{,inspect} and \code{,debug} commands. The inspector is particularly useful with procedures, continuations, and records. The command processor can be taken out of inspection mode by using the \code{q} command. When in inspection mode, input that begins with a letter or digit is read as a command, not as an expression. To see the value of a variable or number, do \code{(begin \cvar{exp})} or use the \code{,run \cvar{exp}} command. In inspection mode the command processor prints out a menu of selectable components for the current focus object. To inspect a particular component, just type the corresponding number in the menu. That component becomes the new focus object. For example: \begin{example} > ,inspect '(a (b c) d) (a (b c) d) [0] a [1] (b c) [2] d : 1 (b c) [0] b [1] c : \end{example} When a new focus object is selected the previous one is pushed onto a stack. You can pop the stack, reverting to the previous object, with the \code{u} command, or use the \code{stack} command to move to an earlier object. %\begin{description} %\item \code{stack}\\ % Prints the current stack out as a menu. % Selecting an item pops all higher values off of the stack and % makes that item the current focus value. %\end{description} % Commands useful when in inspection mode: \begin{itemize} \item\code{u} (up) pop object stack \item\code{m} (more) print more of a long menu \item\code{(\ldots)} evaluate a form and select result \item\code{q} quit \item\code{template} select a closure or continuation's template (Templates are the static components of procedures; these are found inside of procedures and continuations, and contain the quoted constants and top-level variables referred to by byte-compiled code.) \item\code{d} (down) move to the next continuation (current object must be a continuation) \item\code{menu} print the selection menu for the focus object \end{itemize} Multiple selection commands (\code{u}, \code{d}, and menu indexes) may be put on a single line. %\code{\#\#} is always the object currently being inspected. %After a \code{q} %command, %or an error in the inspector, \code{\#\#} is the last object that was being %inspected. All ordinary commands are available when in inspection mode. Similarly, the inspection commands can be used when not in inspection mode. For example: \begin{example} > (list 'a '(b c) 'd) '(a (b c) d) > ,1 '(b c) > ,menu [0] b [1] c > \end{example} If the current command level was initiated because of a breakpoint in the next level down, then \code{,debug} will invoke the inspector on the continuation at the point of the error. The \code{u} and \code{d} (up and down) commands then make the inspected-value stack look like a conventional stack debugger, with continuations playing the role of stack frames. \code{D} goes to older or deeper continuations (frames), and \code{u} goes back up to more recent ones. \section{Command programs} \label{command-programs} The \code{exec} package contains procedures that are used to execute the command processor's commands. A command \code{,\cvar{foo}} is executed by applying the value of the identifier \cvar{foo} in the \code{exec} package to the (suitably parsed) command arguments. \begin{description} \item \code{,exec [\cvar{command}]}\\ Evaluate \cvar{command} in the \code{exec} package. For example, use \begin{example} ,exec ,load \cvar{filename} \end{example} to load a file containing commands. If no \cvar{command} is given, the \code{exec} package becomes the execution package for future commands. \end{description} The required argument types are as follows: \begin{itemize} \item filenames should be strings \item other names and identifiers should be symbols \item expressions should be s-expressions \item commands (as for \code{,config} and \code{,exec} itself) should be lists of the form \code{(\cvar{command-name} \cvar{argument} \cvar{...})} where \cvar{command-name} is a symbol. \end{itemize} For example, the following two commands are equivalent: \begin{example} ,config ,load my-file.scm ,exec (config '(load "my-file.scm")) \end{example} The file \code{scheme/vm/load-vm.scm} in the source directory contains an example of an \code{exec} program. \section{Building images} \begin{description} \item \code{,dump \cvar{filename} [\cvar{identification}]}\\ Writes the current heap out to a file, which can then be run using the virtual machine. The new image file includes the command processor. If present, \cvar{identification} should be a string (written with double quotes); this string will be part of the greeting message as the image starts up. \item \code{,build \cvar{exp} \cvar{filename}}\\ Like \code{,dump}, except that the image file contains the value of \cvar{exp}, which should be a procedure of one argument, instead of the command processor. When \cvar{filename} is resumed, that procedure will be invoked on the VM's \code{-a} arguments, which are passed as a list of strings. The procedure should return an integer which is returned to the program that invoked the VM. The command processor and debugging system are not included in the image (unless you go to some effort to preserve them, such as retaining a continuation). Doing \code{,flush} before building an image will reduce the amount of debugging information in the image, making for a smaller image file, but if an error occurs, the error message may be less helpful. Doing \code{,flush source maps} before loading any programs used in the image will make it still smaller. See \link*{the description of \code{flush}}[section~\Ref]{resource-commands} for more information. \end{description} \section{Resource query and control} \label{resource-commands}. \begin{description} \item \code{,time \cvar{exp}}\\ Measure execution time. \item \code{,collect}\\ Invoke the garbage collector. Ordinarily this happens automatically, but the command tells how much space is available before and after the collection. \item \code{,keep \cvar{kind}} \T\vspace{-1em} \item \code{,flush \cvar{kind}}\\ These control the amount of debugging information retained after compiling procedures. This information can consume a fair amount of space. \cvar{kind} is one of the following: \begin{itemize} \item \code{maps} - environment maps (local variable names, for inspector) \item \code{source} - source code for continuations (displayed by inspector) \item \code{names} - procedure names (as displayed by \code{write} and in error messages) \item \code{files} - source file names \end{itemize} These commands refer to future compilations only, not to procedures that already exist. To have any effect, they must be done before programs are loaded. The default is to keep all four types. % JAR says: ,keep tabulate - puts debug data in a table that can be % independently flushed (how? -RK) or even written out and re-read later! % (how? -RK) \item \code{,flush}\\ The flush command with no argument deletes the database of names of initial procedures. Doing \code{,flush} before a \code{,build} or \code{,dump} will make the resulting image significantly smaller, but will compromise the information content of many error messages. \end{description} \section{Threads} Each command level has its own set of threads. These threads are suspended when a new level is entered and resumed when the owning level again becomes the current level. A thread that raises an error is not resumed unless explicitly restarted using the \code{,proceed} command. In addition to any threads spawned by the user, each level has a thread that runs the command processor on that level. A new command-processor thread is started if the current one dies or is terminated. When a command level is abandoned for a lower level, or when a level is restarted using \code{,reset}, all of the threads on that level are terminated and any \code{dynamic-wind} ``after'' thunks are run. The following commands are useful when debugging multithreaded programs: \begin{description} \item \code{,threads}\\ Invokes the inspector on a list of the threads running at the next lower command level. \item \code{,exit-when-done [\cvar{exp}]}\\ Waits until all user threads have completed and then exits back out to shell (or executive or whatever invoked Scheme~48 in the first place). \cvar{Exp} should evaluate to an integer which is then returned to the calling program. % JAR says: interaction with ,build ? %\item \code{,spawn \cvar{exp} [\cvar{name}]}\\ % Starts a new thread running \cvar{exp} on next command level down. % The optional \cvar{name} is used for printing and debugging. % %\item \code{,suspend [\cvar{exp}]} %\T\vspace{-1em} %\item \code{,continue [\cvar{exp}]} %\T\vspace{-1em} %\item \code{,kill [\cvar{exp}]}\\ % Suspend, unsuspend, and terminate a thread, respectively. % Suspended threads are not run until unsuspended, terminated % threads are never run again. % \cvar{Exp} should evaluate to a thread. % If \cvar{exp} is not present, the current focus object is used. % % example of ,threads ,suspend ... \end{description} \section{Quite obscure} \begin{description} \item \code{,go \cvar{exp}}\\ This is like \code{,exit \cvar{exp}} except that the evaluation of \cvar{exp} is tail-recursive with respect to the command processor. This means that the command processor itself can probably be GC'ed, should a garbage collection occur in the execution of \cvar{exp}. If an error occurs Scheme~48 will exit with a non-zero value. \item \code{,translate \cvar{from} \cvar{to}}\\ For \code{load} and the \code{,load} command (but not for \code{open-\{in|out\}put-file}), file names beginning with the string \cvar{from} will be changed so that the initial \cvar{from} is replaced by the string \cvar{to}. E.g. \begin{example} \code{,translate /usr/gjc/ /zu/gjc/} \end{example} will cause \code{(load "/usr/gjc/foo.scm")} to have the same effect as \code{(load "/zu/gjc/foo.scm")}. % JAR says: Useful with the module system! "virtual directories" \item \code{,from-file \cvar{filename} \cvar{form} \ldots\ ,end}\\ This is used by the \code{cmuscheme48} Emacs library to indicate the file from which the \cvar{form}s came. \cvar{Filename} is then used by the command processor to determine the package in which the \cvar{form}s are to be evaluated. \end{description}
% Stanford University PhD thesis style -- modifications to the report style % This is unofficial so you should always double check against the % Registrar's office rules % See http://library.stanford.edu/research/bibliography-management/latex-and-bibtex % % Example of use below % See the suthesis-2e.sty file for documentation % \documentclass{report} \usepackage{suthesis-2e} % external packages \usepackage{graphicx} % for figures \usepackage[utf8x]{inputenc} % for dealing with unicode in bib file apparently \usepackage[numbers]{natbib} % for citenum \usepackage{bm} % bold greek symbols \usepackage{amsmath} % math stuff \usepackage{hyperref} % url \dept{Applied Physics} \begin{document} \title{Adjoint-Based Optimization and Inverse Design of Photonic Devices} \author{Tyler William Hughes} \principaladviser{Shanhui Fan} \firstreader{Robert L. Byer} \secondreader{Olav Solgaard} % \thirdreader{Mark Brongersma} %if needed % \fourthreader{Amir Safavi-Naeini} %if needed \beforepreface \prefacesection{Abstract} \input{preface/abstract.tex} \prefacesection{Acknowledgments} \input{preface/acknowledgements.tex} \afterpreface \input{commands.tex} % ================ MAIN TEXT ================== % \chapter{Introduction} \input{chapters/1_Introduction.tex} \chapter{Optimization of Laser-Driven Particle Accelerators} \input{chapters/2_ACHIP_adjoint.tex} \chapter{Integrated Photonic Circuit for Accelerators on a Chip} \input{chapters/3_ACHIP_PIC.tex} \chapter{Training of Optical Neural Networks} \input{chapters/4_ONN.tex} \chapter{Wave-Based Analog Recurrent Neural Networks} \input{chapters/5_Wave_RNN} \chapter{Extension of Adjoint Method to Nonlinear Systems} \input{chapters/6_Adjoint_Nonlinear.tex} \chapter{Conclusion and Final Remarks} \input{chapters/7_Conclusion.tex} % ================ APPENDIX =================== % \appendix \chapter{Simulation of Photonic Neural Networks} \input{appendix/1_ANN_Simulation.tex} \chapter{Backpropagation for Nonholomorphic Activations} \input{appendix/2_Nonholomorphic_backprop.tex} % ============== BIBLIOGRAPHY ================= %, \bibliographystyle{plain} \bibliography{bib/bib_main,bib/bib_DLA,bib/bib_tree,bib/bib_MZI,bib/bib_insitu,bib/bib_angler} \end{document}
%mg-rast-api-examples \chapter{Example scripts using the MG-RAST REST API} \label{API-Examples}. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \section{Introduction} As part of the RESTful API (see chapter \ref{API}), we are providing a collection of example scripts. Each script has comments in the source code as well as a help function. This document provides a brief overview of the available scripts and their intended purpose. Please see the help associated with all of the individual files for a complete list of options and more details. We believe these scripts to be the best starting point for many users, he we attempt to provide a listing of the most important tools. \subsection{URLs} The Examples are located on github at: \begin{small} \begin{verbatim} https://github.com/MG-RAST/MG-RAST-Tools \end{verbatim} This is the base directory for the rest of this chapter, go here to find the tools and examples described below: \begin{verbatim} https://github.com/MG-RAST/MG-RAST-Tools/tree/master/tools/bin \end{verbatim} Each script has a verbose help option (--help) to list all options and explain their usage. \end{small} % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \section{Download DNA sequence for a function -- mg-get-sequences-for-function.py} This script will retrieve sequences and annotation for a given function or functional class. The output is a tab-delimited list of: m5nr id, dna sequence, semicolon seperated list of annotations, sequence id. \textbf{Example:} \begin{lstlisting} mg-get-sequences-for-function.py --id "mgm4441680.3" --name "Central carbohydrate metabolism" --level level2 --source Subsystems --evalue 10 \end{lstlisting} % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \section{Download DNA sequences for a taxon or taxonomic group-- mg-get-sequences-for-taxon.py} This script will retrieve sequences and annotation for a given taxon or taxonomic group. The output is a tab-delimited list of: m5nr id, dna sequence, semicolon seperated list of annotations, sequence id \textbf{Example:} \begin{lstlisting} mg-get-sequences-for-taxon.py --id "mgm4441680.3" --name Lachnospiraceae --level family --source RefSeq --evalue 8 \end{lstlisting} % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \section{Download sequences annotated with function and taxonomy -- mg-get-annotation-set.py} Retrieve functional annotations for given metagenome and organism. The output is a tab-delimited list of annotations: feature list, function, abundance for function, avg evalue for function, organism. \textbf{Example:} \begin{lstlisting} mg-get-annotation-set.py --id "mgm4441680.3" --top 5 --level genus --source SEED \end{lstlisting} % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \section{Download the n most abundant functions for a metagenome -- mg-abundant-functions.py} Retrieve the top n abundant functions for metagenome. The output is a tab-delimited list of function and abundance sorted by abundance (largest first). 'top' option controls number of rows returned. \textbf{Example:} \begin{lstlisting} mg-abundant-functions.py --id "mgm4441680.3" --level level3 --source Subsystems --top 20 --evalue 8 \end{lstlisting} % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \section{Download and translate similarities into different namespaces e.g. SEED or GenBank -- m5nr-tools.pl} MG-RAST computes similarities against a non-redundant database \cite{M5NR} and later translates them into any of the supported namespaces. As a result you can view your annotations (or indeed the similarity results) in each of these namespaces. Sometimes this can lead to new features and or differences becoming visible that would otherwise be obscured. m5nr-tools can translate accession ids, md5 checksums, or protein sequence into annotations. One option for output is a blast m8 formatted file. \textbf{Example:} \begin{lstlisting} m5nr-tools.pl --api "https://api.mg-rast.org/1" --option annotation --source RefSeq --md5 0b95101ffea9396db4126e4656460ce5,068792e95e38032059ba7d9c26c1be78,0b96c92ce600d8b2427eedbc221642f1 \end{lstlisting} % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \section{Download multiple abundance profiles for comparison -- mg-compare-functions} Retrieve matrix of functional abundance profiles for multiple metagenomes. The output is either tab-delimited table of functional abundance profiles, metagenomes in columns and functions in rows or BIOM format of functional abundance profiles. \textbf{Example:} \begin{lstlisting} mg-compare-functions.py --ids "mgm4441679.3,mgm4441680.3,mgm4441681.3,mgm4441682.3" --level level2 --source KO --format text --evalue 8 \end{lstlisting}
\chapter{Python Programs} Since Matlab requires a licence, we have also included Python versions of some of the Matlab programs. These programs have been tested in Python 2.7 (which can be obtained from \url{http://python.org/}), they also require Matlplotlib (version 1.10, which can be obtained from \url{http://matplotlib.sourceforge.net/index.html}), Mayavi (\url{http://github.enthought.com/mayavi/mayavi/index.html}) and numpy (\url{http://numpy.scipy.org/}). These programs have been tested primarily with the Enthought Python distribution. \lstinputlisting[style=python_style,language=Python,label=lst:instability,caption={A Python program to demonstrate instability of different time-stepping methods. Compare this to the Matlab implementation in listing \ref{lst:MatlabInstability}.}]{./PythonPrograms/Programs/PythonCode/Simple_ODE_Example_of_Unstable_FE.py} \lstinputlisting[style=python_style,language=Python,label=lst:HeatFE1dPython,caption={A Python program to solve the heat equation using forward Euler time-stepping. Compare this to the Matlab implementation in listing \ref{lst:HeatFE1dMatlab}.}]{./PythonPrograms/Programs/PythonCode/Heat_Eq_1D_Spectral_FE.py} \lstinputlisting[style=python_style,language=Python,label=lst:HeatBE1dPython,caption={A Python program to solve the heat equation using backward Euler time-stepping. Compare this to the Matlab implementation in listing \ref{lst:HeatBE1dMatlab}.}]{./PythonPrograms/Programs/PythonCode/Heat_Eq_1D_Spectral_BE.py} \lstinputlisting[style=python_style,language=Python,label=lst:AllenCahnIE2dPython,caption={A Python program to solve the 2D Allen Cahn equation using implicit explicit time-stepping. Compare this to the Matlab implementation in listing \ref{lst:AllenCahnIE2dMatlab}.}]{./PythonPrograms/Programs/PythonCode/Allen_Cahn_2D_Spectral_IE.py} \lstinputlisting[style=python_style,language=Python,label=lst:BEFPiterPython,caption={A Python program to demonstrate fixed-point iteration. Compare this to the Matlab implementation in listing \ref{lst:BEFPiterMatlab}.}]{./PythonPrograms/Programs/PythonCode/BackwardEulerFixedPoint.py} \lstinputlisting[style=python_style,language=Python,label=lst:BENewIterPython,caption={A Python program to demonstrate Newton iteration. Compare this to the Matlab implementation in listing \ref{lst:BENewIterMatlab}.}]{./PythonPrograms/Programs/PythonCode/BackwardEulerNewtonIteration.py} \lstinputlisting[style=python_style,language=Python,label=lst:OdeStrangPython,caption={A Python program which uses Strang splitting to solve an ODE. Compare this to the Matlab implementation in listing \ref{lst:OdeStrangMatlab}.}]{./PythonPrograms/Programs/PythonCode/ODEsplittingStrang.py} \lstinputlisting[style=python_style,language=Python,label=lst:NlsSplit1DPython,caption={A Python program which uses Strang splitting to solve the one-dimensional nonlinear Schr\"{o}dinger equation. Compare this to the Matlab implementation in listing \ref{lst:NlsSplit1DMatlab}.}]{./PythonPrograms/Programs/PythonCode/NLSsplitting1D.py} \lstinputlisting[style=python_style,language=Python,label=lst:NlsSplit2DPython,caption={A Python program which uses Strang splitting to solve the two-dimensional nonlinear Schr\"{o}dinger equation. Compare this to the Matlab implementation in listing \ref{lst:NlsSplit2DMatlab}.}]{./PythonPrograms/Programs/PythonCode/NLSsplitting2D.py} \lstinputlisting[style=python_style,language=Python,label=lst:NlsSplit3DPython,caption={A Python program which uses Strang splitting to solve the three-dimensional nonlinear Schr\"{o}dinger equation. Compare this to the Matlab implementation in listing \ref{lst:NlsSplit3DMatlab}.}]{./PythonPrograms/Programs/PythonCode/NLSsplitting3D.py} \lstinputlisting[style=python_style,language=Python,label=lst:Ns2DPython,caption={A Python program which finds a numerical solution to the 2D Navier-Stokes equation. Compare this to the Matlab implementation in listing \ref{lst:Ns2DMatlab}.}]{./PythonPrograms/Programs/PythonCode/NavierStokes2DFFTCn.py} \lstinputlisting[style=python_style,language=Python,label=lst:Kg1DPython,caption={A Python program to solve the one-dimensional Klein Gordon equation \eqref{eq:KleinGordon} using the time discretization in eq.\ \eqref{eq:KgImEx}. Compare this to the Matlab implementation in listing \ref{lst:MatKg1D}.}]{./PythonPrograms/Programs/PythonCode/KleinGordon1D.py} \lstinputlisting[style=python_style,language=Python,label=lst:Kg1Dimp,caption={A Python program to solve the one-dimensional Klein Gordon equation \eqref{eq:KleinGordon} using the time discretization in eq.\ \eqref{eq:KgImp}. Compare this to the Matlab implementation in listing \ref{lst:MatKg1Dimp}.}]{./PythonPrograms/Programs/PythonCode/KleinGordon1Dimp.py} \lstinputlisting[style=python_style,language=Python,label=lst:Kg2DPython,caption={A Python program to solve the two-dimensional Klein Gordon equation \eqref{eq:KleinGordon} using the time discretization in eq.\ \eqref{eq:KgImp}. Compare this to the Matlab implementation in listing \ref{lst:MatKg2D}.}]{./PythonPrograms/Programs/PythonCode/KleinGordonImp2Db.py} \lstinputlisting[style=python_style,language=Python,label=lst:Kg2DPython,caption={A Python program to solve the two-dimensional Klein Gordon equation \eqref{eq:KleinGordon} using the time discretization in eq.\ \eqref{eq:KgImp}. Compare this to the Matlab implementation in listing \ref{lst:MatKg2D}.}]{./PythonPrograms/Programs/PythonCode/KleinGordonImp2Db.py} \lstinputlisting[style=python_style,language=Python,label=lst:Kg2DPython,caption={A Python program to solve the two-dimensional Klein Gordon equation \eqref{eq:KleinGordon} using the time discretization in eq.\ \eqref{eq:KgImp}. Compare this to the Matlab implementation in listing \ref{lst:MatKg2D}.}]{./PythonPrograms/Programs/PythonCode/KleinGordonImp2Db.py} \lstinputlisting[style=python_style,language=Python,label=lst:Kg3DPython,caption={A Python program to solve the three-dimensional Klein Gordon equation \eqref{eq:KleinGordon} using the time discretization in eq.\ \eqref{eq:KgImEx}. Compare this to the Matlab implementation in listing \ref{lst:MatKg3D}.}]{./PythonPrograms/Programs/PythonCode/KleinGordonImp3D.py}
%!TEX root = thesis.tex \chapter{Background} \label{ch:Background} This chapter introduces the theory behind the implemented method and the terminology used in this report. The notation used in the report is as follows. Upper-case letters are used for random variables, e.g. $O_t$ for the random variable of observations at time $t$. Lower-case letters are used to indicate specific values of the corresponding random variable, e.g. $o_t$ represents a specific value of the random variable $O_t$. \section{Formulation and Terminology of POMDPs} A Markov decision process (MDP) is a mathematical framework for modeling sequential decision making problems and the framework forms the basis for the POMDP framework, which is a generalization of MDPs. In the MDP framework the state of the world is directly observable whereas in the POMDP framework it is only partially observable. When the state of the world cannot be determined directly a probability distribution over all the possible states of the world must be maintained. More detailed information about POMDPs can be found in \cite{Kaelbling1998} and \cite{Aberdeen2003}. \subsection{The POMDP World Model} \label{sec:POMDPModel} The acting entity in the POMDP world model, the learner, is called an \emph{agent}. The world model in the POMDP framework consists of the following: \begin{itemize} \item $\mathcal{S} = \{1, \dotsc, |\mathcal{S}|\}$ -- States of the world. \item $\mathcal{A} = \{1, \dotsc, |\mathcal{A}|\}$ -- Actions available to the agent. \item $\mathcal{O} = \{1, \dotsc, |\mathcal{O}|\}$ -- Observations the agent can make. \item Reward $r(i) \in \mathds{R}$ for each state $i \in \mathcal{S}$. \end{itemize} At time $t$, in state $S_t$, the agent takes an action $A_t$ according to its policy, makes an observation $O_t$, transitions to a new state $S_{t+1}$ and collects a reward $r(S_{t+1})$ according to the reward function $r(i)$. The state transition is made according to the system dynamics that are modeled by the transition model discussed in \ref{sec:TransitionModel}. Figure \ref{fig:POMDPModel} illustrates this along with the relations between MDPs and POMDPs. \begin{figure}[ht] \centering \includegraphics[width=0.5\textwidth]{figures/pomdp_model} \caption{POMDP diagram. In an MDP the agent would observe the state, $S_t$, directly. In POMDPs the agent makes an observation, $O_t$, that is mapped to the state $S_t$ by a stochastic process. Figure adapted from \cite{Aberdeen2003}.} \label{fig:POMDPModel} \end{figure} To put these concepts into context consider the problem of a robot that needs to find its way out of a maze. In the POMDP world model for that problem the robot is the agent and the state could be the location of the robot in the maze. The actions could be that the robot decides to move in a certain direction or even use one of its sensors. An observation could then be a reading from that sensor. Since this example is easy to grasp it will be used throughout this report where deemed necessary. \subsection{Transition Model} \label{sec:TransitionModel} The transition model defines the probabilities of moving from the current state to any other state of the world for any given action. For each state and action pair $(S_t = i, A_t = k)$ we write the probability of moving from state $i$ to state $j$ when action $A_t = k$ is taken as \begin{equation} p(S_{t+1} = j|S_t = i, A_t = k) \end{equation} When a transition from state $i$ to state $j$ is for some reason impossible given action $k$, this probability is zero. An example of this would be when the agent takes an action that is intended to sense the environment and not move the agent. When the system dynamics prohibit all transitions, i.e. the state never changes, this probability is 1 for $i = j$ and zero otherwise, i.e. \begin{equation} \label{eq:IdentityTransitionModel} p(S_{t+1} = j|S_t = i, A_t = k) = \begin{cases} 1 & \text{if $i = j$}\\ 0 & \text{otherwise} \end{cases} \end{equation} The transition model for a specific problem is generally known or estimated using either empirical data or simply intuition. \subsection{Belief States} Because of the partial observability the agent is unable to determine its current state. However, the observations the agent makes depend on the underlying state so the agent can use the observations to estimate the current state. This estimation is called the agent's belief, or the belief state. \begin{equation*} \mathcal{B} = \{1, \dotsc, |\mathcal{B}|\} \text{ -- Belief states, the agent's belief of the state of the world.} \end{equation*} A single belief state at time $t$, $B_t$, is a probability distribution over all states $i \in \mathcal{S}$. The probability of the state at time $t$ being equal to $i$, given all actions that have been taken and observations that have been made, is defined as \begin{equation} B_t^i \defeq p(S_t = i | A_{1:t}, O_{1:t}) \end{equation} Each time the agent takes an action and makes a new observation it gains more information about the state of the world. The most obvious way to keep track of this information is to store all actions and observations the agent makes, but that results in an unnecessary use of memory and computing power. It is possible to store all the acquired information within the belief state and update it only when necessary, after taking actions and making observations, without storing the whole history of actions and observations. Given the belief state $b_t$, current action $a_t$ and observation $o_t$ the belief for state $j$ can be updated using \begin{equation} \label{eq:UpdateBelief} b_t^j = \frac{ p(o_t | S_t = j, a_t) \sum_{i} p(S_t = j | S_{t-1} = i, a_t) b_{t-1}^i } { p(o_t) } \end{equation} If the state never changes we can simplify equation \eqref{eq:UpdateBelief} to \begin{equation} \label{eq:UpdateBeliefFixedTarget} b_t^j = \frac{ p(o_t | S_t = j, a_t) b_{t-1}^j }{ p(o_t) } \end{equation} where $p(o_t)$ can be treated as a normalization factor. The derivations of \eqref{eq:UpdateBelief} and \eqref{eq:UpdateBeliefFixedTarget} are presented in Appendix \ref{app:BeliefUpdates}. \subsection{Reward Function} \label{sec:RewardFunction} After each state transition the agent gets a reward according to the reward function. These rewards are the agent's indication of its performance and they are generally extrinsic and task-specific. In the case of a robot finding its way out of a maze the reward function might return a small negative reward for all states the robot visits and a large positive reward for the end state, i.e. when the robot is out of the maze, as described in \ref{sec:ModelBasedvsModelFree}. Since the goal is to find a policy that maximizes the expected total rewards the robot will learn to find the shortest path out of the maze. The reward function may depend on the current action and either the current or the resulting state, but it can be made dependent on the resulting state only without loss of generality \cite{Aberdeen2003}. In Section \ref{sec:InformationRewards} we show how a reward function can be made dependent on the belief state only. \subsection{Policy} When it is time for the agent to act it consults its policy. The agent's policy is a mapping from states to actions that defines the agent's behavior. Finding a solution to a POMDP problem is done by finding the optimal policy, i.e. a policy that provides the optimal action for every state the agent visits, or approximating it when finding an exact solution is infeasible. We already know that in POMDPs the agent is unable to determine its current state and a mapping from states to actions is therefore useless for the agent. The straightforward solution to this is to make the policy depend on the belief state. That is typically done by parameterizing the policy as a function of the belief state. Finding or approximating the optimal policy therefore becomes a search for the optimal policy parameters. \subsection{Logistic Policies} \label{sec:LogisticPolicies} One way of parameterizing a policy is to represent it as a function with policy parameters $\theta \in \mathds{R^{|\mathcal{A}| \times |\mathcal{S}|}}$, where $\mathcal{A}$ is the set of actions available to the agent and $\mathcal{S}$ the set of states of the world as presented in \ref{sec:POMDPModel}. Then $\theta$ forms a $|\mathcal{A}| \times |\mathcal{S}|$ matrix which in combination with the current belief state, $b_t$, forms a set of linear functions of the belief state. If $\theta^i$ represents the $i$th row of the matrix $\theta$ then we can select an action according to the policy with \begin{equation} a_{t+1} = \argmax{i} \theta^i \cdot b_t \end{equation} This is a deterministic policy since it will always result in the same action for a particular belief state $b_t$. However, if we need a stochastic policy -- as is the case for the policy gradient method described in \ref{sec:GradientAscent} -- we can represent it as a logistic function using the policy parameters $\theta$ and the current belief state, $b_t$. Again, if $\theta^i$ represents the $i$th row of the matrix $\theta$ then the probability of taking action $k$ is given by \begin{equation} \label{eq:LogisticPolicy} p(A_{t+1} = k | b_t, \theta) = \frac{ \exp{(\theta^k \cdot b_t)} }{ \sum_{i=1}^{|\mathcal{A}|}{ \exp{( \theta^i \cdot b_t}) }} \end{equation} where $b_t$ is the agent's belief. This is a probability distribution that represents a stochastic policy. Taking an action based on this stochastic policy is done by sampling from the probability distribution. The key to estimating the policy gradient in equation \eqref{eq:PolicyGradient} lies in calculating the gradient of equation \eqref{eq:LogisticPolicy} with respect to $\theta$, as shown in \cite{Butko2010b}. \subsection{Observation Model} \label{sec:ObservationModel} When training a policy, the agent must be able to make observations. The sensors the agent uses to observe the world are in general imperfect and noisy which means that when the agent makes an observation it has to assume some uncertainty. The observations available to the agent can be actual readings from its sensors -- and that is the case when the agent is put to work in the real world -- but during training, having a model that can generate observations is preferred. This is called an observation model and its purpose is to model the noisy behavior of the actual sensors. The observation model needs to be estimated or trained using real data acquired by the agent's sensors before training the policy. \subsection{Observation Likelihood} \label{sec:ObservationLikelihood} The observation likelihood is the probability of making observation $O_t$ after the agent takes action $A_t$ in state $S_{t}$, \begin{equation} p(O_t|S_t, A_t) \end{equation} given the current observation model. \subsection{Model-based vs. Model-free} \label{sec:ModelBasedvsModelFree} When the observation model, the transition model and the reward function $r(i)$ are all known, the POMDP is considered to be \emph{model-based}. Otherwise the POMDP is said to be \emph{model-free}. A model-free POMDP can learn a policy without a full model of the world by sampling trajectories through the state space, either by interacting with the world or using a simulator. To give an example, consider our robot friend again that needs to find its way out of a maze. If the robot receives a small negative reward in each state it visits and a large positive reward when it gets out, it can learn a policy by exploring the maze without necessarily knowing the transition model or observation model. The POMDPs considered in this report are always model-based. \section{Policy Gradient} \label{sec:PolicyGradient} Methods for finding exact optimal solutions to POMDPs exist but they become infeasible for problems with large state- and action-spaces and they require full knowledge of the system dynamics, such as the transition model and the reward function. When either of those requirements are not fulfilled, reinforcement learning can be used to estimate the optimal policy. The methods used, when exact methods are infeasible, are either value function methods or direct policy search. Value function methods require the agent to assign a value to each state and action pair and this value represents the long term expected reward for taking an action in a given state. In every state the agent chooses the action that has the highest value given the state, so the policy is essentially extracted from the value function. As the state-space grows larger the value function becomes more complex, making it more challenging to learn. However, the policy-space does not necessarily become more complex, making it more desirable to search the policy-space directly \cite{Aberdeen2003}. An algorithm for a direct policy search using gradient ascent was presented in \cite{BaxterB2001} and used in \cite{Butko2010b}. The algorithm generates an estimate of the gradient of the average reward with respect to the policy and using gradient ascent the policy is improved iteratively. This requires a parameterized representation of the policy. \subsection{Gradient Ascent} \label{sec:GradientAscent} If the policy is parameterized by $\theta$, for example as described in \ref{sec:LogisticPolicies}, the average reward of the policy can be written as \begin{equation} \underbrace{\eta(\theta)}_{\mathclap{\substack{\text{Average} \\ \text{reward}}}} = \sum_{x \in X} \underbrace{r(x)}_{\text{reward}} \overbrace{p(x | \theta)}^{\substack{\text{prob. of $x$} \\ \text{given policy}}} = \Ex [r(x)] \end{equation} where $x$ represents the parameters that the reward function depends on. In our case $x$ is the agent's belief, $b$. The gradient of the average reward given the parameterized policy $\theta$ is therefore \begin{align} \nabla \eta(\theta) &= \sum_{b \in \mathcal{B}} r(b) \nabla p(b | \theta) \\ &= \sum_{b \in \mathcal{B}} r(b) \frac{\nabla p(b | \theta)}{p(b | \theta)} p(b | \theta) \\ &= \Ex \bigg{[}r(b) \frac{\nabla p(b | \theta)}{p(b | \theta)}\bigg{]} \end{align} If we generate $N$ i.i.d. samples from $p(b | \theta)$ then we can estimate $\nabla \eta(\theta)$ by \begin{equation} \widetilde{\nabla} \eta(\theta) = \frac{1}{N} \sum_{i=1}^N r(b_i) \frac{\nabla p(b_i | \theta)}{p(b_i | \theta)} \Bigg{\}} \substack{\text{given fixed $\theta$} \\ \text{we sample $b_i$} \\ \text{and we estimate} \\ \text{$\nabla \eta(\theta)$}} \end{equation} with $N \to \infty$, $\widetilde{\nabla} \eta(\theta) \to \nabla \eta(\theta)$. \\\\ Assume a regenerative process, each i.i.d. $b_i$ is now a sequence $b_i^1 \dotsc b_i^{M_i}$. We get \begin{equation} \widetilde{\nabla} \eta(\theta) = \frac{1}{N} \sum_{i=1}^N r(b_i^1, \dotsc, b_i^{M_i}) \sum_{j=1}^{M_i} \frac{\nabla p(b_i^j | \theta)}{p(b_i^j | \theta)} \end{equation} If we assume \begin{equation} r(b_i^1, \dotsc, b_i^{M_i}) = f\Big{(} \underbrace{r(b_i^1, \dotsc, b_i^{M_{i-1}})}_{r_i^{M_{i-1}}}, b_i^{M_i}\Big{)} \end{equation} and write \begin{equation} \sum_{j=1}^{M_i} \frac{\nabla p(b_i^j | \theta)}{p(b_i^j | \theta)} = Z_i^{M_i} = Z_i^{M_{i-1}} + \frac{\nabla p(b_i^{M_i} | \theta)}{p(b_i^{M_i} | \theta)} \end{equation} we have \begin{equation} \widetilde{\nabla} \eta(\theta) = \frac{1}{N} \sum_{i=1}^N \underbrace{r_i^{M_i} Z_i^{M_i}}_{\substack{\text{Computed} \\ \text{iteratively}}} \bigg{\}} \frac{1}{N} \widetilde{\nabla}_N \end{equation} where \begin{equation} r_i^{M_{i}} = r(b_i^1, \dotsc, b_i^{M_i}) \end{equation} This gives an unbiased estimate of the policy gradient \begin{equation} \label{eq:GradientEstimate} \underbrace{\widetilde{\nabla}_N}_{\substack{\text{Computed} \\ \text{iteratively}}} = \widetilde{\nabla}_{N-1} + r_N^{M_N} Z_N^{M_N} \end{equation} The estimate of the gradient of the average reward, $\widetilde{\nabla}_N$, can therefore be computed iteratively and the policy parameters $\theta$ updated by a simple update rule \begin{equation} \label{eq:PolicyGradient} \theta_{new} = \theta + \frac{\widetilde{\nabla}_N}{N} \end{equation} where $N$ is the number of samples used to estimate the gradient, i.e. the number of episodes. When training a policy using gradient ascent the gradient of the average reward is estimated from a number of episodes, during which the policy parameters are kept fixed. When all episodes have finished the policy parameters are updated using the gradient estimation and that concludes one training iteration, a so called epoch. The gradient estimate is what has been referred to as the policy gradient. \section{Infomax Control} Using the theory of optimal control in combination with information maximization is known as \emph{Infomax control} \cite{Movellan2005}. The idea is to treat the task of learning as a control problem where the goal is to derive a policy that seeks to maximize information, or equivalently, reduce the total uncertainty. The POMDP models that are used for this purpose are information gathering POMDPs and have been called Infomax POMDPs, or I-POMDPs \cite{Butko2010b}. \section{Information Rewards} \label{sec:InformationRewards} Conceptually, the POMDP world issues rewards to the agent as it interacts with the world and these rewards are generally task-specific. In order to make an information-driven POMDP, an I-POMDP, the reward function must depend on the amount of information the agent gathers. The way this is done is to make the reward a function of the agent's belief of the world. The entropy of the agent's belief at each point in time becomes the reward the agent receives. As the agent becomes more and more certain about the state of the world, the higher reward the agent receives. This principle is what drives the learning of information gathering strategies. The policy gradient is used to adjust the current policy and the reward, i.e. the certainty of the agent's belief, controls the magnitude of the adjustment. This is shown in equation \eqref{eq:GradientEstimate}. The information reward function becomes \begin{equation} \label{eq:InformationRewards} r_t(b_t) = \sum_{j=1}^{|\mathcal{S}|} b_t^j \log_2{b_t^j} \end{equation} where $\mathcal{S}$ is the set of states of the world and $b_t$ is the agent's belief at time $t$. Care needs to be taken when calculating the logarithm of the belief in practice because as the agent becomes more certain about the state of the world, most of the values of the belief vector $b_t$ approach zero. As the precision of numbers stored in computers varies, we might have the situation where some of those values are actually stored as zero. Therefore, when calculating the rewards we define \begin{equation} \log_2{0} \defeq 0 \end{equation}
% Created with <3 by Anthony Kung % % On January 10 for ECE 341 @ OSU % % Define Document % \documentclass{article} \usepackage[utf8]{inputenc} \usepackage[legalpaper, margin=0.5in]{geometry} % Get Rid Of Numbering % % \pagenumbering{gobble} % % No Paragraph Indent % \setlength{\parindent}{0pt} % Images Setup % \usepackage{graphicx} \graphicspath{ {./images/} } \usepackage{float} % Define Colors % \usepackage[dvipsnames]{xcolor} \definecolor{DeepPink}{HTML}{FF1493} \definecolor{RoyalBlue}{HTML}{4169E1} \definecolor{DodgerBlue}{HTML}{1E90FF} \definecolor{Background}{HTML}{212121} % Color Setup % % Dark Theme % \pagecolor{Background} \color{white} % Font Setup % \usepackage{tgbonum} \renewcommand{\familydefault}{\sfdefault} \usepackage{listings} % Caption Setup % \usepackage{caption} \usepackage[font={color=white},figurename=Figure]{caption} \captionsetup{belowskip=-40pt} % List of Figures Format % % \renewcommand{\listfigurename}{ % % Footer % \usepackage{fancyhdr} \pagestyle{fancy} \fancyhf{} \rfoot{\centering\textcolor{white}{Page \thepage}} % Hyperlink Setup % \usepackage{hyperref} \hypersetup{ colorlinks=true, linkcolor=RoyalBlue, filecolor=DeepPink, urlcolor=cyan, pdftitle={ECE 341 Week 1 Lab Report}, % REPLACE THIS % bookmarks=true, pdfpagemode=FullScreen, } % Preamble % \title{ECE 341 Week 1 Lab Report} % REPLACE THIS % \author{ Anthony Kung % REPLACE THIS % } \date{January 10, 2021} % REPLACE THIS % % Actual Document % \begin{document} \fontfamily{qag}\selectfont %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % DOCUMENT STARTS HERE % DOCUMENT STARTS HERE % DOCUMENT STARTS HERE % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Week 1 Lab Report % REPLACE THIS % \newline \textbf{Written by}: Anthony Kung % REPLACE THIS % \hfill \textbf{Date Performed}: January 10, 2021 % REPLACE THIS % \textbf{Instructor}: Brandilyn Coker \hfill \textbf{T.A.}: Shane Witsell \begin{center} \large\textbf{ECE 341 Week 1 Lab Report} % REPLACE THIS % \\ \end{center} \setlength{\parskip}{1em} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % BEGIN YOUR REPORT % BEGIN YOUR REPORT % BEGIN YOUR REPORT % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \section{\textbf{\textit{Introduction of Lab Objectives and Activities}}} \section{\textbf{\textit{Background and Pre-Lab}}} \section{\textbf{\textit{Procedure}}} \section{\textbf{\textit{Results and Analysis}}} \section{\textbf{\textit{Conclusion}}} % END YOUR REPORT % \end{document}
\subsection{Zero to the zero power} The following example draws a graph of the function $f(x)=|x^x|$. The graph shows why the convention $0^0=1$ makes sense. \begin{Verbatim}[formatcom=\color{blue},samepage=true] f(x) = abs(x^x) xrange = (-2,2) yrange = (-2,2) draw(f,x) \end{Verbatim} \begin{center} \includegraphics[scale=0.2]{zerozero.png} \end{center} We can see how $0^0=1$ results in a continuous line through $x=0$. Now let us see how $x^x$ behaves in the complex plane. \begin{Verbatim}[formatcom=\color{blue},samepage=true] f(t) = (real(t^t),imag(t^t)) xrange = (-2,2) yrange = (-2,2) trange = (-4,2) draw(f,t) \end{Verbatim} \begin{center} \includegraphics[scale=0.2]{zerozero2.png} \end{center}
% Default to the notebook output style % Inherit from the specified cell style. \documentclass[11pt]{article} \usepackage[T1]{fontenc} % Nicer default font (+ math font) than Computer Modern for most use cases \usepackage{mathpazo} % Basic figure setup, for now with no caption control since it's done % automatically by Pandoc (which extracts ![](path) syntax from Markdown). \usepackage{graphicx} % We will generate all images so they have a width \maxwidth. This means % that they will get their normal width if they fit onto the page, but % are scaled down if they would overflow the margins. \makeatletter \def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth \else\Gin@nat@width\fi} \makeatother \let\Oldincludegraphics\includegraphics % Ensure that by default, figures have no caption (until we provide a % proper Figure object with a Caption API and a way to capture that % in the conversion process - todo). \usepackage{caption} \DeclareCaptionLabelFormat{nolabel}{} \captionsetup{labelformat=nolabel} \usepackage{adjustbox} % Used to constrain images to a maximum size \usepackage{xcolor} % Allow colors to be defined \usepackage{enumerate} % Needed for markdown enumerations to work \usepackage{geometry} % Used to adjust the document margins \usepackage{amsmath} % Equations \usepackage{amssymb} % Equations \usepackage{textcomp} % defines textquotesingle % Hack from http://tex.stackexchange.com/a/47451/13684: \AtBeginDocument{% \def\PYZsq{\textquotesingle}% Upright quotes in Pygmentized code } \usepackage{upquote} % Upright quotes for verbatim code \usepackage{eurosym} % defines \euro \usepackage[mathletters]{ucs} % Extended unicode (utf-8) support \usepackage[utf8x]{inputenc} % Allow utf-8 characters in the tex document \usepackage{fancyvrb} % verbatim replacement that allows latex \usepackage{grffile} % extends the file name processing of package graphics % to support a larger range % The hyperref package gives us a pdf with properly built % internal navigation ('pdf bookmarks' for the table of contents, % internal cross-reference links, web links for URLs, etc.) \usepackage{hyperref} \usepackage{longtable} % longtable support required by pandoc >1.10 \usepackage{booktabs} % table support for pandoc > 1.12.2 \usepackage[inline]{enumitem} % IRkernel/repr support (it uses the enumerate* environment) \usepackage[normalem]{ulem} % ulem is needed to support strikethroughs (\sout) % normalem makes italics be italics, not underlines \usepackage{mathrsfs} \usepackage{pdflscape} \usepackage{placeins} % Colors for the hyperref package \definecolor{urlcolor}{rgb}{0,.145,.698} \definecolor{linkcolor}{rgb}{.71,0.21,0.01} \definecolor{citecolor}{rgb}{.12,.54,.11} % ANSI colors \definecolor{ansi-black}{HTML}{3E424D} \definecolor{ansi-black-intense}{HTML}{282C36} \definecolor{ansi-red}{HTML}{E75C58} \definecolor{ansi-red-intense}{HTML}{B22B31} \definecolor{ansi-green}{HTML}{00A250} \definecolor{ansi-green-intense}{HTML}{007427} \definecolor{ansi-yellow}{HTML}{DDB62B} \definecolor{ansi-yellow-intense}{HTML}{B27D12} \definecolor{ansi-blue}{HTML}{208FFB} \definecolor{ansi-blue-intense}{HTML}{0065CA} \definecolor{ansi-magenta}{HTML}{D160C4} \definecolor{ansi-magenta-intense}{HTML}{A03196} \definecolor{ansi-cyan}{HTML}{60C6C8} \definecolor{ansi-cyan-intense}{HTML}{258F8F} \definecolor{ansi-white}{HTML}{C5C1B4} \definecolor{ansi-white-intense}{HTML}{A1A6B2} \definecolor{ansi-default-inverse-fg}{HTML}{FFFFFF} \definecolor{ansi-default-inverse-bg}{HTML}{000000} % commands and environments needed by pandoc snippets % extracted from the output of `pandoc -s` \providecommand{\tightlist}{% \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}} \DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}} % Add ',fontsize=\small' for more characters per line \newenvironment{Shaded}{}{} \newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{\textbf{{#1}}}} \newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.56,0.13,0.00}{{#1}}} \newcommand{\DecValTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{{#1}}} \newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{{#1}}} \newcommand{\FloatTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{{#1}}} \newcommand{\CharTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}} \newcommand{\StringTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}} \newcommand{\CommentTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textit{{#1}}}} \newcommand{\OtherTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{{#1}}} \newcommand{\AlertTok}[1]{\textcolor[rgb]{1.00,0.00,0.00}{\textbf{{#1}}}} \newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.02,0.16,0.49}{{#1}}} \newcommand{\RegionMarkerTok}[1]{{#1}} \newcommand{\ErrorTok}[1]{\textcolor[rgb]{1.00,0.00,0.00}{\textbf{{#1}}}} \newcommand{\NormalTok}[1]{{#1}} % Additional commands for more recent versions of Pandoc \newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.53,0.00,0.00}{{#1}}} \newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}} \newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}} \newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.73,0.40,0.53}{{#1}}} \newcommand{\ImportTok}[1]{{#1}} \newcommand{\DocumentationTok}[1]{\textcolor[rgb]{0.73,0.13,0.13}{\textit{{#1}}}} \newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{{#1}}}}} \newcommand{\CommentVarTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{{#1}}}}} \newcommand{\VariableTok}[1]{\textcolor[rgb]{0.10,0.09,0.49}{{#1}}} \newcommand{\ControlFlowTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{\textbf{{#1}}}} \newcommand{\OperatorTok}[1]{\textcolor[rgb]{0.40,0.40,0.40}{{#1}}} \newcommand{\BuiltInTok}[1]{{#1}} \newcommand{\ExtensionTok}[1]{{#1}} \newcommand{\PreprocessorTok}[1]{\textcolor[rgb]{0.74,0.48,0.00}{{#1}}} \newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.49,0.56,0.16}{{#1}}} \newcommand{\InformationTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{{#1}}}}} \newcommand{\WarningTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{{#1}}}}} % Define a nice break command that doesn't care if a line doesn't already % exist. \def\br{\hspace*{\fill} \\* } % Math Jax compatibility definitions \def\gt{>} \def\lt{<} \let\Oldtex\TeX \let\Oldlatex\LaTeX \renewcommand{\TeX}{\textrm{\Oldtex}} \renewcommand{\LaTeX}{\textrm{\Oldlatex}} % Document parameters % Document title \title{FinalProjectAnalysis} % Pygments definitions \makeatletter \def\PY@reset{\let\PY@it=\relax \let\PY@bf=\relax% \let\PY@ul=\relax \let\PY@tc=\relax% \let\PY@bc=\relax \let\PY@ff=\relax} \def\PY@tok#1{\csname PY@tok@#1\endcsname} \def\PY@toks#1+{\ifx\relax#1\empty\else% \PY@tok{#1}\expandafter\PY@toks\fi} \def\PY@do#1{\PY@bc{\PY@tc{\PY@ul{% \PY@it{\PY@bf{\PY@ff{#1}}}}}}} \def\PY#1#2{\PY@reset\PY@toks#1+\relax+\PY@do{#2}} \expandafter\def\csname PY@tok@w\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.73,0.73}{##1}}} \expandafter\def\csname PY@tok@c\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}} \expandafter\def\csname PY@tok@cp\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.74,0.48,0.00}{##1}}} \expandafter\def\csname PY@tok@k\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} \expandafter\def\csname PY@tok@kp\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} \expandafter\def\csname PY@tok@kt\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.69,0.00,0.25}{##1}}} \expandafter\def\csname PY@tok@o\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} \expandafter\def\csname PY@tok@ow\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.67,0.13,1.00}{##1}}} \expandafter\def\csname PY@tok@nb\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} \expandafter\def\csname PY@tok@nf\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}} \expandafter\def\csname PY@tok@nc\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}} \expandafter\def\csname PY@tok@nn\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}} \expandafter\def\csname PY@tok@ne\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.82,0.25,0.23}{##1}}} \expandafter\def\csname PY@tok@nv\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} \expandafter\def\csname PY@tok@no\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.53,0.00,0.00}{##1}}} \expandafter\def\csname PY@tok@nl\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.63,0.63,0.00}{##1}}} \expandafter\def\csname PY@tok@ni\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.60,0.60,0.60}{##1}}} \expandafter\def\csname PY@tok@na\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.49,0.56,0.16}{##1}}} \expandafter\def\csname PY@tok@nt\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} \expandafter\def\csname PY@tok@nd\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.67,0.13,1.00}{##1}}} \expandafter\def\csname PY@tok@s\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} \expandafter\def\csname PY@tok@sd\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} \expandafter\def\csname PY@tok@si\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.73,0.40,0.53}{##1}}} \expandafter\def\csname PY@tok@se\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.73,0.40,0.13}{##1}}} \expandafter\def\csname PY@tok@sr\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.40,0.53}{##1}}} \expandafter\def\csname PY@tok@ss\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} \expandafter\def\csname PY@tok@sx\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} \expandafter\def\csname PY@tok@m\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} \expandafter\def\csname PY@tok@gh\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,0.50}{##1}}} \expandafter\def\csname PY@tok@gu\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.50,0.00,0.50}{##1}}} \expandafter\def\csname PY@tok@gd\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.63,0.00,0.00}{##1}}} \expandafter\def\csname PY@tok@gi\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.63,0.00}{##1}}} \expandafter\def\csname PY@tok@gr\endcsname{\def\PY@tc##1{\textcolor[rgb]{1.00,0.00,0.00}{##1}}} \expandafter\def\csname PY@tok@ge\endcsname{\let\PY@it=\textit} \expandafter\def\csname PY@tok@gs\endcsname{\let\PY@bf=\textbf} \expandafter\def\csname PY@tok@gp\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,0.50}{##1}}} \expandafter\def\csname PY@tok@go\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.53,0.53,0.53}{##1}}} \expandafter\def\csname PY@tok@gt\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.27,0.87}{##1}}} \expandafter\def\csname PY@tok@err\endcsname{\def\PY@bc##1{\setlength{\fboxsep}{0pt}\fcolorbox[rgb]{1.00,0.00,0.00}{1,1,1}{\strut ##1}}} \expandafter\def\csname PY@tok@kc\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} \expandafter\def\csname PY@tok@kd\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} \expandafter\def\csname PY@tok@kn\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} \expandafter\def\csname PY@tok@kr\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} \expandafter\def\csname PY@tok@bp\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} \expandafter\def\csname PY@tok@fm\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}} \expandafter\def\csname PY@tok@vc\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} \expandafter\def\csname PY@tok@vg\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} \expandafter\def\csname PY@tok@vi\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} \expandafter\def\csname PY@tok@vm\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} \expandafter\def\csname PY@tok@sa\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} \expandafter\def\csname PY@tok@sb\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} \expandafter\def\csname PY@tok@sc\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} \expandafter\def\csname PY@tok@dl\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} \expandafter\def\csname PY@tok@s2\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} \expandafter\def\csname PY@tok@sh\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} \expandafter\def\csname PY@tok@s1\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} \expandafter\def\csname PY@tok@mb\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} \expandafter\def\csname PY@tok@mf\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} \expandafter\def\csname PY@tok@mh\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} \expandafter\def\csname PY@tok@mi\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} \expandafter\def\csname PY@tok@il\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} \expandafter\def\csname PY@tok@mo\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} \expandafter\def\csname PY@tok@ch\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}} \expandafter\def\csname PY@tok@cm\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}} \expandafter\def\csname PY@tok@cpf\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}} \expandafter\def\csname PY@tok@c1\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}} \expandafter\def\csname PY@tok@cs\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}} \def\PYZbs{\char`\\} \def\PYZus{\char`\_} \def\PYZob{\char`\{} \def\PYZcb{\char`\}} \def\PYZca{\char`\^} \def\PYZam{\char`\&} \def\PYZlt{\char`\<} \def\PYZgt{\char`\>} \def\PYZsh{\char`\#} \def\PYZpc{\char`\%} \def\PYZdl{\char`\$} \def\PYZhy{\char`\-} \def\PYZsq{\char`\'} \def\PYZdq{\char`\"} \def\PYZti{\char`\~} % for compatibility with earlier versions \def\PYZat{@} \def\PYZlb{[} \def\PYZrb{]} \makeatother % Exact colors from NB \definecolor{incolor}{rgb}{0.0, 0.0, 0.5} \definecolor{outcolor}{rgb}{0.545, 0.0, 0.0} % Prevent overflowing lines due to hard-to-break entities \sloppy % Setup hyperref package \hypersetup{ breaklinks=true, % so long urls are correctly broken across lines colorlinks=true, urlcolor=urlcolor, linkcolor=linkcolor, citecolor=citecolor, } % Slightly bigger margins than the latex defaults \geometry{verbose,tmargin=1in,bmargin=1in,lmargin=1in,rmargin=1in} \begin{document} \maketitle \hypertarget{analysis-of-colors-present-in-fractal-artwork}{% \section{Analysis of Colors Present in Fractal Artwork}\label{analysis-of-colors-present-in-fractal-artwork}} \hypertarget{cs496---special-topics}{% \subsection{CS496 - Special Topics}\label{cs496---special-topics}} \hypertarget{by-madison-tibbett}{% \subsubsection{by Madison Tibbett}\label{by-madison-tibbett}} \hypertarget{source-of-data}{% \subsection{Source of Data}\label{source-of-data}} All datasets were sourced from the author's own home computer. All artworks present and analyzed are property of Madison Tibbett, (c) 2010-2020. All artworks presented are protected under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 License. You can read more about the licensing \href{https://creativecommons.org/licenses/by-nc-nd/3.0/}{here}. All processing code for this project can be found on \href{https://github.com/Esherymack/color-analyzer}{GitHub}, where it is covered by the Unlicense. All artworks retain their Creative Commons licensing despite the Unlicense on the codebase. The processing code is not included in this report due to the weight of processing the image data. \hypertarget{resources}{% \subsubsection{Resources}\label{resources}} \begin{itemize} \tightlist \item https://towardsdatascience.com/color-identification-in-images-machine-learning-application-b26e770c4c71 \item https://www.dataquest.io/blog/tutorial-colors-image-clustering-python/ \item https://realpython.com/python-opencv-color-spaces/ \end{itemize} \hypertarget{purpose-of-the-project}{% \subsubsection{Purpose of the project}\label{purpose-of-the-project}} I have been creating fractal artwork for over ten years now, and I was curious as to any particular trends in my use of color over the decade. I decided then to utilize a KMeans clustering algorithm to determine the most common colors in a given image, find the peak color, match it to a named color, and then classify it based on that color's color family. I then graphed the results. \hypertarget{libraries-used-for-processing}{% \subsubsection{Libraries used for processing:}\label{libraries-used-for-processing}} For processing the data, I made use of several data-science specific libraries, including: \begin{itemize} \tightlist \item \href{https://scikit-learn.org/stable/}{sklearn} \item \href{https://matplotlib.org/}{matplotlib} \item \href{https://numpy.org/}{numpy} \item \href{https://opencv.org/}{opencv2} \item \href{https://scikit-image.org/}{scikit-image} \end{itemize} \begin{Verbatim}[commandchars=\\\{\}] {\color{incolor}In [{\color{incolor}2}]:} \PY{c+c1}{\PYZsh{} The following magic is required to display graphs and charts} \PY{c+c1}{\PYZsh{} inline with Jupyter.} \PY{o}{\PYZpc{}}\PY{k}{matplotlib} inline \PY{k+kn}{import} \PY{n+nn}{matplotlib}\PY{n+nn}{.}\PY{n+nn}{pyplot} \PY{k}{as} \PY{n+nn}{plt} \PY{k+kn}{import} \PY{n+nn}{numpy} \PY{k}{as} \PY{n+nn}{np} \PY{k+kn}{import} \PY{n+nn}{cv2} \PY{k+kn}{import} \PY{n+nn}{os} \PY{c+c1}{\PYZsh{} not necessary, but I enjoy fivethirtyeight styling over} \PY{c+c1}{\PYZsh{} matplotlib default.} \PY{n}{plt}\PY{o}{.}\PY{n}{style}\PY{o}{.}\PY{n}{use}\PY{p}{(}\PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{fivethirtyeight}\PY{l+s+s2}{\PYZdq{}}\PY{p}{)} \end{Verbatim} \hypertarget{the-first-task}{% \subsubsection{The first task}\label{the-first-task}} The first task in processing my images was to actually get a KMeans algorithm clustering colors in any given image. To do this, I opted to use the KMeans methods built-in to sklearn. In order to open images, I used a for loop. \begin{Shaded} \begin{Highlighting}[] \NormalTok{ i }\OperatorTok{=} \DecValTok{0} \BuiltInTok{print}\NormalTok{(os.getcwd())} \ControlFlowTok{for}\NormalTok{ filename }\KeywordTok{in}\NormalTok{ os.listdir(image_data_directory):} \ControlFlowTok{if}\NormalTok{ filename.endswith(}\StringTok{".jpg"}\NormalTok{):} \NormalTok{ image }\OperatorTok{=}\NormalTok{ get_image(}\SpecialStringTok{f'}\SpecialCharTok{\{}\NormalTok{image_data_directory}\SpecialCharTok{\}}\SpecialStringTok{/}\SpecialCharTok{\{}\NormalTok{filename}\SpecialCharTok{\}}\SpecialStringTok{'}\NormalTok{)} \BuiltInTok{print}\NormalTok{(}\StringTok{"------------------------------"}\NormalTok{)} \BuiltInTok{print}\NormalTok{(}\SpecialStringTok{f"Input image: }\SpecialCharTok{\{}\NormalTok{filename}\SpecialCharTok{\}}\SpecialStringTok{"}\NormalTok{)} \BuiltInTok{print}\NormalTok{(}\SpecialStringTok{f"Shape: }\SpecialCharTok{\{}\NormalTok{image}\SpecialCharTok{.}\NormalTok{shape}\SpecialCharTok{\}}\SpecialStringTok{"}\NormalTok{)} \NormalTok{ get_colors(image, }\DecValTok{10}\NormalTok{, i)} \BuiltInTok{print}\NormalTok{(}\StringTok{"------------------------------"}\NormalTok{)} \NormalTok{ i}\OperatorTok{+=}\DecValTok{1} \end{Highlighting} \end{Shaded} Within the for loop, a function called \texttt{get\_colors()} actually handles running the algorithm. This loop steps through a given directory and processes each image individually; I debated multithreading, but not only does sklearn's machine learning algorithms not work well with Python's built-in task managing library, it already seems to be mildly multithreaded as running the main work script used 50\% of my computer's processing power. I also am a lazy programmer, and didn't feel like refactoring my code to be multithreaded after writing it. The \texttt{get\_colors()} method is as follows: \begin{Shaded} \begin{Highlighting}[] \KeywordTok{def}\NormalTok{ get_colors(image, ncolors, fname):} \CommentTok{# Resizing images to lessen pixel count,} \CommentTok{# which reduces the time needed to extract} \CommentTok{# colors from image.} \NormalTok{ modified_image }\OperatorTok{=}\NormalTok{ cv2.resize(image, (}\DecValTok{600}\NormalTok{, }\DecValTok{400}\NormalTok{), } \NormalTok{ interpolation }\OperatorTok{=}\NormalTok{ cv2.INTER_AREA)} \NormalTok{ modified_image }\OperatorTok{=}\NormalTok{ modified_image.reshape} \NormalTok{ (modified_image.shape[}\DecValTok{0}\NormalTok{] }\OperatorTok{*}\NormalTok{ modified_image.shape[}\DecValTok{1}\NormalTok{], }\DecValTok{3}\NormalTok{)} \NormalTok{ clf }\OperatorTok{=}\NormalTok{ KMeans(n_clusters }\OperatorTok{=}\NormalTok{ ncolors)} \NormalTok{ labels }\OperatorTok{=}\NormalTok{ clf.fit_predict(modified_image)} \NormalTok{ counts }\OperatorTok{=}\NormalTok{ Counter(labels)} \NormalTok{ center_colors }\OperatorTok{=}\NormalTok{ clf.cluster_centers_} \NormalTok{ ordered_colors }\OperatorTok{=}\NormalTok{ [center_colors[i] }\ControlFlowTok{for}\NormalTok{ i }\KeywordTok{in}\NormalTok{ counts.keys()]} \NormalTok{ hex_colors }\OperatorTok{=}\NormalTok{ [RGB2HEX(ordered_colors[i]) }\ControlFlowTok{for}\NormalTok{ i }\KeywordTok{in}\NormalTok{ counts.keys()]} \NormalTok{ rgb_colors }\OperatorTok{=}\NormalTok{ [ordered_colors[i] }\ControlFlowTok{for}\NormalTok{ i }\KeywordTok{in}\NormalTok{ counts.keys()]} \NormalTok{ dictionary }\OperatorTok{=} \BuiltInTok{dict}\NormalTok{(}\BuiltInTok{zip}\NormalTok{(hex_colors, counts.values()))} \NormalTok{ dictionary }\OperatorTok{=} \BuiltInTok{dict}\NormalTok{(}\BuiltInTok{sorted}\NormalTok{(dictionary.items(),} \NormalTok{ key }\OperatorTok{=}\NormalTok{ operator.itemgetter(}\DecValTok{1}\NormalTok{), reverse }\OperatorTok{=} \VariableTok{True}\NormalTok{))} \ControlFlowTok{for}\NormalTok{ k, v }\KeywordTok{in}\NormalTok{ dictionary.items():} \BuiltInTok{print}\NormalTok{(}\SpecialStringTok{f"Color: }\SpecialCharTok{\{k\}}\SpecialStringTok{; Count: }\SpecialCharTok{\{v\}}\SpecialStringTok{"}\NormalTok{)} \NormalTok{ hexes }\OperatorTok{=} \BuiltInTok{list}\NormalTok{(dictionary.keys())} \NormalTok{ Peak(hexes[}\DecValTok{0}\NormalTok{], fname)} \NormalTok{ plt.figure(figsize }\OperatorTok{=}\NormalTok{ (}\DecValTok{8}\NormalTok{, }\DecValTok{6}\NormalTok{))} \NormalTok{ plt.pie(counts.values(), labels}\OperatorTok{=}\NormalTok{hex_colors, colors }\OperatorTok{=}\NormalTok{ hex_colors)} \NormalTok{ plt.savefig(}\SpecialStringTok{f"./analyzed2/piecharts/}\SpecialCharTok{\{}\NormalTok{fname}\SpecialCharTok{\}}\SpecialStringTok{.jpg"}\NormalTok{)} \NormalTok{ plt.close()} \ControlFlowTok{return}\NormalTok{ rgb_colors} \end{Highlighting} \end{Shaded} Within this function, the pie charts in the attached appendix are created. Each pie chart represents the \emph{n} most common colors in a given image as selected by the KMeans algorithm. KMeans is a sort-of-random algorithm in that it will pick a relatively arbitrary location in the image and work from there. This means that there sometimes is a fluctuation in the actual counts of colors. While I was testing on a smaller dataset (1 to 5 images at a time), I noticed that the fluctuations would happen, but were relatively infrequent, which gave me confidence. However, to offset this slight statistical issue, I ran each test 5 times. This is reflected in the appendix. \hypertarget{the-second-task}{% \subsubsection{The second task}\label{the-second-task}} The second task after getting the most popular colours in an image was to find the ``peak'' color. This is a simple matter of picking the highest-counted color in the image. I then proceeded to match each ``peak'' color to a ``named'' color. The ``named'' colors were pulled from a massive list of color names and hex values found on Wikipedia. You can view these many lists \href{https://en.wikipedia.org/wiki/Lists_of_colors}{here}. I simply did this for my own amusement. I like when colors have names. \begin{Shaded} \begin{Highlighting}[] \KeywordTok{def}\NormalTok{ Peak(peaked_color, fname):} \NormalTok{ r }\OperatorTok{=}\NormalTok{ [}\BuiltInTok{int}\NormalTok{(}\BuiltInTok{hex}\NormalTok{[}\DecValTok{0}\NormalTok{:}\DecValTok{2}\NormalTok{], }\DecValTok{16}\NormalTok{) }\ControlFlowTok{for} \BuiltInTok{hex} \KeywordTok{in}\NormalTok{ hex_rgb_colors] } \CommentTok{# Red elements} \NormalTok{ g }\OperatorTok{=}\NormalTok{ [}\BuiltInTok{int}\NormalTok{(}\BuiltInTok{hex}\NormalTok{[}\DecValTok{2}\NormalTok{:}\DecValTok{4}\NormalTok{], }\DecValTok{16}\NormalTok{) }\ControlFlowTok{for} \BuiltInTok{hex} \KeywordTok{in}\NormalTok{ hex_rgb_colors] } \CommentTok{# Green elements} \NormalTok{ b }\OperatorTok{=}\NormalTok{ [}\BuiltInTok{int}\NormalTok{(}\BuiltInTok{hex}\NormalTok{[}\DecValTok{4}\NormalTok{:}\DecValTok{6}\NormalTok{], }\DecValTok{16}\NormalTok{) }\ControlFlowTok{for} \BuiltInTok{hex} \KeywordTok{in}\NormalTok{ hex_rgb_colors] } \CommentTok{# Blue elements} \NormalTok{ r }\OperatorTok{=}\NormalTok{ np.asarray(r, np.uint8)} \NormalTok{ g }\OperatorTok{=}\NormalTok{ np.asarray(g, np.uint8)} \NormalTok{ b }\OperatorTok{=}\NormalTok{ np.asarray(b, np.uint8)} \NormalTok{ rgb }\OperatorTok{=}\NormalTok{ np.dstack((r, g, b))} \NormalTok{ lab }\OperatorTok{=}\NormalTok{ rgb2lab(rgb)} \NormalTok{ peaked_rgb }\OperatorTok{=}\NormalTok{ np.asarray([}\BuiltInTok{int}\NormalTok{(peaked_color[}\DecValTok{1}\NormalTok{:}\DecValTok{3}\NormalTok{], }\DecValTok{16}\NormalTok{), } \BuiltInTok{int}\NormalTok{(peaked_color[}\DecValTok{3}\NormalTok{:}\DecValTok{5}\NormalTok{], }\DecValTok{16}\NormalTok{,), }\BuiltInTok{int}\NormalTok{(peaked_color[}\DecValTok{5}\NormalTok{:}\DecValTok{7}\NormalTok{], } \DecValTok{16}\NormalTok{)], np.uint8)} \NormalTok{ peaked_rgb }\OperatorTok{=}\NormalTok{ np.dstack((peaked_rgb[}\DecValTok{0}\NormalTok{], peaked_rgb[}\DecValTok{1}\NormalTok{], } \NormalTok{ peaked_rgb[}\DecValTok{2}\NormalTok{]))} \NormalTok{ peaked_lab }\OperatorTok{=}\NormalTok{ rgb2lab(peaked_rgb)} \CommentTok{# Compute Euclidean distance} \NormalTok{ lab_dist }\OperatorTok{=}\NormalTok{ ((lab[:,:,}\DecValTok{0}\NormalTok{] }\OperatorTok{-}\NormalTok{ peaked_lab[:,:,}\DecValTok{0}\NormalTok{])}\OperatorTok{**}\DecValTok{2} \OperatorTok{+} \NormalTok{ (lab[:,:,}\DecValTok{1}\NormalTok{] }\OperatorTok{-}\NormalTok{ peaked_lab[:,:,}\DecValTok{1}\NormalTok{])}\OperatorTok{**}\DecValTok{2} \OperatorTok{+}\NormalTok{ (lab[:,:,}\DecValTok{2}\NormalTok{] }\OperatorTok{-} \NormalTok{ peaked_lab[:,:,}\DecValTok{2}\NormalTok{])}\OperatorTok{**}\DecValTok{2}\NormalTok{)}\OperatorTok{**}\FloatTok{0.5} \CommentTok{# Get index of min distance} \NormalTok{ min_index }\OperatorTok{=}\NormalTok{ lab_dist.argmin()} \CommentTok{# Get the hex string of the color with the minimum Euclidean distance } \NormalTok{ peaked_closest_hex }\OperatorTok{=}\NormalTok{ hex_rgb_colors[min_index]} \CommentTok{# Get the color name from the dictionary} \NormalTok{ peaked_color_name }\OperatorTok{=}\NormalTok{ colors_dict[peaked_closest_hex]} \NormalTok{ peaked_color_rgb }\OperatorTok{=}\NormalTok{ HEX2RGB(peaked_color)} \NormalTok{ closest_match }\OperatorTok{=}\NormalTok{ HEX2RGB(}\BuiltInTok{list}\NormalTok{(colors_dict.keys())} \NormalTok{ [}\BuiltInTok{list}\NormalTok{(colors_dict.values()).index(peaked_color_name)])} \BuiltInTok{print}\NormalTok{(}\SpecialStringTok{f"Peaked color name: }\SpecialCharTok{\{}\NormalTok{peaked_color_name}\SpecialCharTok{\}}\SpecialStringTok{"}\NormalTok{)} \NormalTok{ h, s, v }\OperatorTok{=}\NormalTok{ RGB2HSV(peaked_closest_hex)} \BuiltInTok{print}\NormalTok{(}\SpecialStringTok{f"The top color is }\SpecialCharTok{\{}\NormalTok{peaked_color_name}\SpecialCharTok{\}}\SpecialStringTok{. } \SpecialStringTok{ Its HSV is }\SpecialCharTok{\{h\}}\SpecialStringTok{, }\SpecialCharTok{\{s\}}\SpecialStringTok{, }\SpecialCharTok{\{v\}}\SpecialStringTok{."}\NormalTok{)} \NormalTok{ colorFamily }\OperatorTok{=}\NormalTok{ determinedColorFamily(h, s, v)} \BuiltInTok{print}\NormalTok{(}\SpecialStringTok{f"The determined color family of } \SpecialStringTok{ }\SpecialCharTok{\{}\NormalTok{peaked_color_name}\SpecialCharTok{\}}\SpecialStringTok{ is }\SpecialCharTok{\{}\NormalTok{colorFamily}\SpecialCharTok{\}}\SpecialStringTok{"}\NormalTok{)} \BuiltInTok{print}\NormalTok{(}\SpecialStringTok{f"R: }\SpecialCharTok{\{}\NormalTok{peaked_color_rgb[}\DecValTok{0}\NormalTok{]}\SpecialCharTok{\}}\SpecialStringTok{, G: } \SpecialStringTok{ }\SpecialCharTok{\{}\NormalTok{peaked_color_rgb[}\DecValTok{1}\NormalTok{]}\SpecialCharTok{\}}\SpecialStringTok{, B: }\SpecialCharTok{\{}\NormalTok{peaked_color_rgb[}\DecValTok{2}\NormalTok{]}\SpecialCharTok{\}}\SpecialStringTok{"}\NormalTok{)} \BuiltInTok{print}\NormalTok{(}\SpecialStringTok{f"R: }\SpecialCharTok{\{}\NormalTok{closest_match[}\DecValTok{0}\NormalTok{]}\SpecialCharTok{\}}\SpecialStringTok{, G: }\SpecialCharTok{\{}\NormalTok{closest_match[}\DecValTok{1}\NormalTok{]}\SpecialCharTok{\}}\SpecialStringTok{, } \SpecialStringTok{ B: }\SpecialCharTok{\{}\NormalTok{closest_match[}\DecValTok{2}\NormalTok{]}\SpecialCharTok{\}}\SpecialStringTok{"}\NormalTok{)} \NormalTok{ fig, ax }\OperatorTok{=}\NormalTok{ plt.subplots(nrows}\OperatorTok{=}\DecValTok{1}\NormalTok{, ncols}\OperatorTok{=}\DecValTok{2}\NormalTok{)} \NormalTok{ Z }\OperatorTok{=}\NormalTok{ np.vstack([peaked_color_rgb[}\DecValTok{0}\NormalTok{], peaked_color_rgb[}\DecValTok{1}\NormalTok{],} \NormalTok{ peaked_color_rgb[}\DecValTok{2}\NormalTok{]])} \NormalTok{ Y }\OperatorTok{=}\NormalTok{ np.vstack([closest_match[}\DecValTok{0}\NormalTok{], closest_match[}\DecValTok{1}\NormalTok{], } \NormalTok{ closest_match[}\DecValTok{2}\NormalTok{]])} \NormalTok{ ax[}\DecValTok{0}\NormalTok{].set_title(}\SpecialStringTok{f'Color from image: }\SpecialCharTok{\{}\NormalTok{peaked_color_rgb[}\DecValTok{0}\NormalTok{]}\SpecialCharTok{\}} \SpecialStringTok{ ,}\SpecialCharTok{\{}\NormalTok{peaked_color_rgb[}\DecValTok{1}\NormalTok{]}\SpecialCharTok{\}}\SpecialStringTok{,}\SpecialCharTok{\{}\NormalTok{peaked_color_rgb[}\DecValTok{2}\NormalTok{]}\SpecialCharTok{\}}\SpecialStringTok{'}\NormalTok{, fontsize}\OperatorTok{=}\DecValTok{12}\NormalTok{)} \NormalTok{ ax[}\DecValTok{0}\NormalTok{].imshow(np.dstack(Z), interpolation }\OperatorTok{=} \StringTok{'none'}\NormalTok{, aspect }\OperatorTok{=} \StringTok{'auto'}\NormalTok{)} \NormalTok{ ax[}\DecValTok{1}\NormalTok{].set_title(}\SpecialStringTok{f'Color matched to }\SpecialCharTok{\{}\NormalTok{closest_match[}\DecValTok{0}\NormalTok{]}\SpecialCharTok{\}}\SpecialStringTok{,} \SpecialStringTok{ }\SpecialCharTok{\{}\NormalTok{closest_match[}\DecValTok{1}\NormalTok{]}\SpecialCharTok{\}}\SpecialStringTok{,}\SpecialCharTok{\{}\NormalTok{closest_match[}\DecValTok{2}\NormalTok{]}\SpecialCharTok{\}}\SpecialStringTok{'}\NormalTok{, fontsize}\OperatorTok{=}\DecValTok{12}\NormalTok{)} \NormalTok{ ax[}\DecValTok{1}\NormalTok{].imshow(np.dstack(Y), interpolation }\OperatorTok{=} \StringTok{'none'}\NormalTok{, aspect }\OperatorTok{=} \StringTok{'auto'}\NormalTok{)} \NormalTok{ fig.suptitle(}\SpecialStringTok{f"Peaked color name: }\SpecialCharTok{\{}\NormalTok{peaked_color_name}\SpecialCharTok{\}}\SpecialStringTok{"}\NormalTok{, fontsize}\OperatorTok{=}\DecValTok{16}\NormalTok{)} \NormalTok{ ax[}\DecValTok{0}\NormalTok{].axis(}\StringTok{'off'}\NormalTok{)} \NormalTok{ ax[}\DecValTok{0}\NormalTok{].grid(b}\OperatorTok{=}\VariableTok{None}\NormalTok{)} \NormalTok{ ax[}\DecValTok{1}\NormalTok{].axis(}\StringTok{'off'}\NormalTok{)} \NormalTok{ ax[}\DecValTok{1}\NormalTok{].grid(b}\OperatorTok{=}\VariableTok{None}\NormalTok{)} \NormalTok{ plt.savefig(}\SpecialStringTok{f"./analyzed2/peaks/}\SpecialCharTok{\{}\NormalTok{fname}\SpecialCharTok{\}}\SpecialStringTok{.jpg"}\NormalTok{)} \NormalTok{ plt.close()} \end{Highlighting} \end{Shaded} \hypertarget{the-third-task}{% \subsubsection{The third task}\label{the-third-task}} The final task I wanted to accomplish was to actually count how many times a popular colour appeared over the entire dataset. I opted to use the HSV color space to figure this out. Because each of my named colours has a known and consistent hex value, I decided to cluster those instead of the actual peak color. Judging from my own results, the peak color is typically ``close enough'' to the point that I feel comfortable in this decision. To convert colors from the RGB colorspace to the HSV colorspace, I used the following algorithm: \begin{Shaded} \begin{Highlighting}[] \KeywordTok{def}\NormalTok{ RGB2HSV(color):} \NormalTok{ r, g, b }\OperatorTok{=}\NormalTok{ HEX2RGB(color)} \CommentTok{# Convert RGB values to percentages} \NormalTok{ r }\OperatorTok{=}\NormalTok{ r }\OperatorTok{/} \DecValTok{255} \NormalTok{ g }\OperatorTok{=}\NormalTok{ g }\OperatorTok{/} \DecValTok{255} \NormalTok{ b }\OperatorTok{=}\NormalTok{ b }\OperatorTok{/} \DecValTok{255} \CommentTok{# calculate a few basic values; the max of r, g, b, } \CommentTok{# the min value, and the difference between the two (chroma)} \NormalTok{ maxRGB }\OperatorTok{=} \BuiltInTok{max}\NormalTok{(r, g, b)} \NormalTok{ minRGB }\OperatorTok{=} \BuiltInTok{min}\NormalTok{(r, g, b)} \NormalTok{ chroma }\OperatorTok{=}\NormalTok{ maxRGB }\OperatorTok{-}\NormalTok{ minRGB} \CommentTok{# value (brightness) is easiest to calculate,} \CommentTok{# it's simply the highest value among the r, g, b components} \CommentTok{# multiply by 100 to turn the decimal into a percent} \NormalTok{ computedValue }\OperatorTok{=} \DecValTok{100} \OperatorTok{*}\NormalTok{ maxRGB} \CommentTok{# there's a special case for hueless (equal parts RGB make} \CommentTok{# black, white, or grey)} \CommentTok{# note that hue is technically undefined when chroma is 0} \CommentTok{# as attempting to calc it would simply cause a division by 0} \CommentTok{# error, so most applications} \CommentTok{# simply sub a hue of 0} \CommentTok{# Saturation will always be 0 in this case} \ControlFlowTok{if}\NormalTok{ chroma }\OperatorTok{==} \DecValTok{0}\NormalTok{:} \ControlFlowTok{return} \DecValTok{0}\NormalTok{, }\DecValTok{0}\NormalTok{, computedValue} \CommentTok{# Saturation is also simple to compute, as it is chroma/value} \NormalTok{ computedSaturation }\OperatorTok{=} \DecValTok{100} \OperatorTok{*}\NormalTok{ (chroma}\OperatorTok{/}\NormalTok{maxRGB)} \CommentTok{# Calculate hue} \CommentTok{# Hue is calculated via "chromacity" represented as a } \CommentTok{# 2D hexagon, divided into six 60-deg sectors} \CommentTok{# we calculate the bisecting angle as a value 0 <= x < 6, } \CommentTok{# which represents which protion} \CommentTok{# of the sector the line falls on} \ControlFlowTok{if}\NormalTok{ r }\OperatorTok{==}\NormalTok{ minRGB:} \NormalTok{ h }\OperatorTok{=} \DecValTok{3} \OperatorTok{-}\NormalTok{ ((g }\OperatorTok{-}\NormalTok{ b) }\OperatorTok{/}\NormalTok{ chroma)} \ControlFlowTok{elif}\NormalTok{ b }\OperatorTok{==}\NormalTok{ minRGB:} \NormalTok{ h }\OperatorTok{=} \DecValTok{1} \OperatorTok{-}\NormalTok{ ((r }\OperatorTok{-}\NormalTok{ g) }\OperatorTok{/}\NormalTok{ chroma)} \ControlFlowTok{else}\NormalTok{:} \NormalTok{ h }\OperatorTok{=} \DecValTok{5} \OperatorTok{-}\NormalTok{ ((b }\OperatorTok{-}\NormalTok{ r) }\OperatorTok{/}\NormalTok{ chroma)} \CommentTok{# After we have each sector position, we multiply it by } \CommentTok{# the size of each sector's arc to obtain the angle in degrees} \NormalTok{ computedHue }\OperatorTok{=} \DecValTok{60} \OperatorTok{*}\NormalTok{ h} \ControlFlowTok{return}\NormalTok{ computedHue, computedSaturation, computedValue} \end{Highlighting} \end{Shaded} The function returns a tuple that consists of the calculated hue, saturation, and value. After this was acquired, I could then simply classify each color based on its HSV. I used the following HSV chart to help me match my named colors to a more general ``color family.'' \begin{figure} \centering \includegraphics{PKjgfFXm.png} \end{figure} By using this chart, I was able to then construct a method that consists of an increasingly painful chain of if/else if statements to then tally each braod color family. \begin{Shaded} \begin{Highlighting}[] \KeywordTok{def}\NormalTok{ determinedColorFamily(hue, sat, val):} \ControlFlowTok{if}\NormalTok{ hue }\OperatorTok{==} \DecValTok{0} \KeywordTok{and}\NormalTok{ sat }\OperatorTok{==} \DecValTok{0}\NormalTok{:} \ControlFlowTok{if}\NormalTok{ val }\OperatorTok{>=} \DecValTok{95}\NormalTok{:} \NormalTok{ families_dict[}\StringTok{"white"}\NormalTok{] }\OperatorTok{+=} \DecValTok{1} \ControlFlowTok{return} \StringTok{"white"} \ControlFlowTok{elif} \DecValTok{15} \OperatorTok{<=}\NormalTok{ val }\OperatorTok{<} \DecValTok{95}\NormalTok{:} \NormalTok{ families_dict[}\StringTok{"grey"}\NormalTok{] }\OperatorTok{+=} \DecValTok{1} \ControlFlowTok{return} \StringTok{"grey"} \ControlFlowTok{else}\NormalTok{:} \NormalTok{ families_dict[}\StringTok{"black"}\NormalTok{] }\OperatorTok{+=} \DecValTok{1} \ControlFlowTok{return} \StringTok{"black"} \ControlFlowTok{elif} \DecValTok{0} \OperatorTok{<=}\NormalTok{ val }\OperatorTok{<} \DecValTok{15}\NormalTok{:} \NormalTok{ families_dict[}\StringTok{"black"}\NormalTok{] }\OperatorTok{+=} \DecValTok{1} \ControlFlowTok{return} \StringTok{"black"} \ControlFlowTok{elif} \DecValTok{99} \OperatorTok{<=}\NormalTok{ val }\OperatorTok{<=} \DecValTok{100} \KeywordTok{and} \DecValTok{0} \OperatorTok{<=}\NormalTok{ sat }\OperatorTok{<} \DecValTok{5}\NormalTok{:} \NormalTok{ families_dict[}\StringTok{"white"}\NormalTok{] }\OperatorTok{+=} \DecValTok{1} \ControlFlowTok{return} \StringTok{"white"} \ControlFlowTok{elif} \DecValTok{5} \OperatorTok{<=}\NormalTok{ sat }\OperatorTok{<=} \DecValTok{100}\NormalTok{:} \ControlFlowTok{if} \DecValTok{0} \OperatorTok{<=}\NormalTok{ hue }\OperatorTok{<} \DecValTok{15}\NormalTok{:} \NormalTok{ families_dict[}\StringTok{"red"}\NormalTok{] }\OperatorTok{+=} \DecValTok{1} \ControlFlowTok{return} \StringTok{"red"} \ControlFlowTok{elif} \DecValTok{15} \OperatorTok{<=}\NormalTok{ hue }\OperatorTok{<} \DecValTok{30}\NormalTok{:} \NormalTok{ families_dict[}\StringTok{"warm red"}\NormalTok{] }\OperatorTok{+=} \DecValTok{1} \ControlFlowTok{return} \StringTok{"warm red"} \ControlFlowTok{elif} \DecValTok{30} \OperatorTok{<=}\NormalTok{ hue }\OperatorTok{<} \DecValTok{45}\NormalTok{:} \NormalTok{ families_dict[}\StringTok{"orange"}\NormalTok{] }\OperatorTok{+=} \DecValTok{1} \ControlFlowTok{return} \StringTok{"orange"} \ControlFlowTok{elif} \DecValTok{45} \OperatorTok{<=}\NormalTok{ hue }\OperatorTok{<} \DecValTok{60}\NormalTok{:} \NormalTok{ families_dict[}\StringTok{"warm yellow"}\NormalTok{] }\OperatorTok{+=} \DecValTok{1} \ControlFlowTok{return} \StringTok{"warm yellow"} \ControlFlowTok{elif} \DecValTok{60} \OperatorTok{<=}\NormalTok{ hue }\OperatorTok{<} \DecValTok{75}\NormalTok{:} \NormalTok{ families_dict[}\StringTok{"yellow"}\NormalTok{] }\OperatorTok{+=} \DecValTok{1} \ControlFlowTok{return} \StringTok{"yellow"} \ControlFlowTok{elif} \DecValTok{75} \OperatorTok{<=}\NormalTok{ hue }\OperatorTok{<} \DecValTok{90}\NormalTok{:} \NormalTok{ families_dict[}\StringTok{"cool yellow"}\NormalTok{] }\OperatorTok{+=} \DecValTok{1} \ControlFlowTok{return} \StringTok{"cool yellow"} \ControlFlowTok{elif} \DecValTok{90} \OperatorTok{<=}\NormalTok{ hue }\OperatorTok{<} \DecValTok{105}\NormalTok{:} \NormalTok{ families_dict[}\StringTok{"yellow green"}\NormalTok{] }\OperatorTok{+=} \DecValTok{1} \ControlFlowTok{return} \StringTok{"yellow green"} \ControlFlowTok{elif} \DecValTok{105} \OperatorTok{<=}\NormalTok{ hue }\OperatorTok{<} \DecValTok{120}\NormalTok{:} \NormalTok{ families_dict[}\StringTok{"warm green"}\NormalTok{] }\OperatorTok{+=} \DecValTok{1} \ControlFlowTok{return} \StringTok{"warm green"} \ControlFlowTok{elif} \DecValTok{120} \OperatorTok{<=}\NormalTok{ hue }\OperatorTok{<} \DecValTok{135}\NormalTok{:} \NormalTok{ families_dict[}\StringTok{"green"}\NormalTok{] }\OperatorTok{+=} \DecValTok{1} \ControlFlowTok{return} \StringTok{"green"} \ControlFlowTok{elif} \DecValTok{135} \OperatorTok{<=}\NormalTok{ hue }\OperatorTok{<} \DecValTok{150}\NormalTok{:} \NormalTok{ families_dict[}\StringTok{"cool green"}\NormalTok{] }\OperatorTok{+=} \DecValTok{1} \ControlFlowTok{return} \StringTok{"cool green"} \ControlFlowTok{elif} \DecValTok{150} \OperatorTok{<=}\NormalTok{ hue }\OperatorTok{<} \DecValTok{165}\NormalTok{:} \NormalTok{ families_dict[}\StringTok{"green cyan"}\NormalTok{] }\OperatorTok{+=} \DecValTok{1} \ControlFlowTok{return} \StringTok{"green cyan"} \ControlFlowTok{elif} \DecValTok{165} \OperatorTok{<=}\NormalTok{ hue }\OperatorTok{<} \DecValTok{180}\NormalTok{:} \NormalTok{ families_dict[}\StringTok{"warm cyan"}\NormalTok{] }\OperatorTok{+=} \DecValTok{1} \ControlFlowTok{return} \StringTok{"warm cyan"} \ControlFlowTok{elif} \DecValTok{180} \OperatorTok{<=}\NormalTok{ hue }\OperatorTok{<} \DecValTok{195}\NormalTok{:} \NormalTok{ families_dict[}\StringTok{"cyan"}\NormalTok{] }\OperatorTok{+=} \DecValTok{1} \ControlFlowTok{return} \StringTok{"cyan"} \ControlFlowTok{elif} \DecValTok{195} \OperatorTok{<=}\NormalTok{ hue }\OperatorTok{<} \DecValTok{210}\NormalTok{:} \NormalTok{ families_dict[}\StringTok{"cool cyan"}\NormalTok{] }\OperatorTok{+=} \DecValTok{1} \ControlFlowTok{return} \StringTok{"cool cyan"} \ControlFlowTok{elif} \DecValTok{210} \OperatorTok{<=}\NormalTok{ hue }\OperatorTok{<} \DecValTok{225}\NormalTok{:} \NormalTok{ families_dict[}\StringTok{"blue cyan"}\NormalTok{] }\OperatorTok{+=} \DecValTok{1} \ControlFlowTok{return} \StringTok{"blue cyan"} \ControlFlowTok{elif} \DecValTok{225} \OperatorTok{<=}\NormalTok{ hue }\OperatorTok{<} \DecValTok{240}\NormalTok{:} \NormalTok{ families_dict[}\StringTok{"cool blue"}\NormalTok{] }\OperatorTok{+=} \DecValTok{1} \ControlFlowTok{return} \StringTok{"cool blue"} \ControlFlowTok{elif} \DecValTok{240} \OperatorTok{<=}\NormalTok{ hue }\OperatorTok{<} \DecValTok{255}\NormalTok{:} \NormalTok{ families_dict[}\StringTok{"blue"}\NormalTok{] }\OperatorTok{+=} \DecValTok{1} \ControlFlowTok{return} \StringTok{"blue"} \ControlFlowTok{elif} \DecValTok{255} \OperatorTok{<=}\NormalTok{ hue }\OperatorTok{<} \DecValTok{270}\NormalTok{:} \NormalTok{ families_dict[}\StringTok{"warm blue"}\NormalTok{] }\OperatorTok{+=} \DecValTok{1} \ControlFlowTok{return} \StringTok{"warm blue"} \ControlFlowTok{elif} \DecValTok{270} \OperatorTok{<=}\NormalTok{ hue }\OperatorTok{<} \DecValTok{285}\NormalTok{:} \NormalTok{ families_dict[}\StringTok{"violet"}\NormalTok{] }\OperatorTok{+=} \DecValTok{1} \ControlFlowTok{return} \StringTok{"violet"} \ControlFlowTok{elif} \DecValTok{285} \OperatorTok{<=}\NormalTok{ hue }\OperatorTok{<} \DecValTok{300}\NormalTok{:} \NormalTok{ families_dict[}\StringTok{"cool magenta"}\NormalTok{] }\OperatorTok{+=} \DecValTok{1} \ControlFlowTok{return} \StringTok{"cool magenta"} \ControlFlowTok{elif} \DecValTok{300} \OperatorTok{<=}\NormalTok{ hue }\OperatorTok{<} \DecValTok{315}\NormalTok{:} \NormalTok{ families_dict[}\StringTok{"magenta"}\NormalTok{] }\OperatorTok{+=} \DecValTok{1} \ControlFlowTok{return} \StringTok{"magenta"} \ControlFlowTok{elif} \DecValTok{315} \OperatorTok{<=}\NormalTok{ hue }\OperatorTok{<} \DecValTok{330}\NormalTok{:} \NormalTok{ families_dict[}\StringTok{"warm magenta"}\NormalTok{] }\OperatorTok{+=} \DecValTok{1} \ControlFlowTok{return} \StringTok{"warm magenta"} \ControlFlowTok{elif} \DecValTok{330} \OperatorTok{<=}\NormalTok{ hue }\OperatorTok{<} \DecValTok{345}\NormalTok{:} \NormalTok{ families_dict[}\StringTok{"red magenta"}\NormalTok{] }\OperatorTok{+=} \DecValTok{1} \ControlFlowTok{return} \StringTok{"red magenta"} \ControlFlowTok{elif} \DecValTok{345} \OperatorTok{<=}\NormalTok{ hue }\OperatorTok{<=} \DecValTok{360}\NormalTok{:} \NormalTok{ families_dict[}\StringTok{"cool red"}\NormalTok{] }\OperatorTok{+=} \DecValTok{1} \ControlFlowTok{return} \StringTok{"cool red"} \ControlFlowTok{elif} \DecValTok{0} \OperatorTok{<=}\NormalTok{ sat }\OperatorTok{<} \DecValTok{5}\NormalTok{:} \NormalTok{ families_dict[}\StringTok{"grey"}\NormalTok{] }\OperatorTok{+=} \DecValTok{1} \ControlFlowTok{return} \StringTok{"grey"} \end{Highlighting} \end{Shaded} \hypertarget{and-thats-pretty-much-it.}{% \subsubsection{And that's pretty much it.}\label{and-thats-pretty-much-it.}} After all was said and done, I created another simple script which just took the saved data from each run and averaged each result. The final graph looks like this: \begin{landscape} \begin{figure} \centering \includegraphics[width=8in]{./analyzed2/average_analysis.jpg} \end{figure} \end{landscape} And the final counts, since it may be a bit difficult to determine just from looking at the graph any exact numbers: \begin{itemize} \tightlist \item White: 4 \item Grey: 17 \item Black: 91 \item Red: 73 \item Warm Red: 53 \item Orange: 30 \item Warm yellow: 12 \item Yellow: 3 \item Cool Yellow: 6 \item Yellow Green: 6 \item Warm Green: 0 \item Green: 2 \item Cool Green: 4 \item Green Cyan: 7 \item Warm Cyan: 5 \item Cyan: 18 \item Cool Cyan: 25 \item Blue Cyan: 18 \item Cool Blue: 14 \item Blue: 5 \item Warm Blue: 1 \item Violet: 3 \item Cool Magenta: 12 \item Magenta: 4 \item Warm Magenta: 5 \item Red Magenta: 7 \item Cool Red: 16 \end{itemize} Overall, would I say I agree with these results? Yeah. I tend to use a lot of dark colours, and in my classifications I did cluster anything that I deemed ``very very dark'' to be ``black.'' This is a general assumption that I feel many viewers may make. \hypertarget{appendix}{% \subsection{Appendix}\label{appendix}} The following code will generate images using matplotlib that hold the source image, each image's 5 pie charts, and each image's 5 peaks. \begin{Verbatim}[commandchars=\\\{\}] {\color{incolor}In [{\color{incolor}5}]:} \PY{k}{def} \PY{n+nf}{get\PYZus{}image}\PY{p}{(}\PY{n}{image\PYZus{}path}\PY{p}{)}\PY{p}{:} \PY{n}{image} \PY{o}{=} \PY{n}{cv2}\PY{o}{.}\PY{n}{imread}\PY{p}{(}\PY{n}{image\PYZus{}path}\PY{p}{)} \PY{c+c1}{\PYZsh{} By default, OpenCV reads image sequence as BGR} \PY{c+c1}{\PYZsh{} To view the actual image we need to convert} \PY{c+c1}{\PYZsh{} to RGB} \PY{n}{image} \PY{o}{=} \PY{n}{cv2}\PY{o}{.}\PY{n}{cvtColor}\PY{p}{(}\PY{n}{image}\PY{p}{,} \PY{n}{cv2}\PY{o}{.}\PY{n}{COLOR\PYZus{}BGR2RGB}\PY{p}{)} \PY{k}{return} \PY{n}{image} \PY{n}{c} \PY{o}{=} \PY{l+m+mi}{0} \PY{k}{for} \PY{n}{filename} \PY{o+ow}{in} \PY{n}{os}\PY{o}{.}\PY{n}{listdir}\PY{p}{(}\PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{./data}\PY{l+s+s2}{\PYZdq{}}\PY{p}{)}\PY{p}{:} \PY{k}{if} \PY{n}{filename}\PY{o}{.}\PY{n}{endswith}\PY{p}{(}\PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{.jpg}\PY{l+s+s2}{\PYZdq{}}\PY{p}{)}\PY{p}{:} \PY{n}{image} \PY{o}{=} \PY{n}{get\PYZus{}image}\PY{p}{(}\PY{n}{f}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{./data/}\PY{l+s+si}{\PYZob{}filename\PYZcb{}}\PY{l+s+s1}{\PYZsq{}}\PY{p}{)} \PY{n}{fname} \PY{o}{=} \PY{n+nb}{str}\PY{p}{(}\PY{n}{c}\PY{p}{)} \PY{o}{+} \PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{.jpg}\PY{l+s+s2}{\PYZdq{}} \PY{n}{c} \PY{o}{+}\PY{o}{=} \PY{l+m+mi}{1} \PY{n}{first\PYZus{}pie} \PY{o}{=} \PY{n}{get\PYZus{}image}\PY{p}{(}\PY{n}{f}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{./data\PYZus{}runs/first/piecharts/}\PY{l+s+si}{\PYZob{}fname\PYZcb{}}\PY{l+s+s1}{\PYZsq{}}\PY{p}{)} \PY{n}{second\PYZus{}pie} \PY{o}{=} \PY{n}{get\PYZus{}image}\PY{p}{(}\PY{n}{f}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{./data\PYZus{}runs/second/piecharts/}\PY{l+s+si}{\PYZob{}fname\PYZcb{}}\PY{l+s+s1}{\PYZsq{}}\PY{p}{)} \PY{n}{third\PYZus{}pie} \PY{o}{=} \PY{n}{get\PYZus{}image}\PY{p}{(}\PY{n}{f}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{./data\PYZus{}runs/third/piecharts/}\PY{l+s+si}{\PYZob{}fname\PYZcb{}}\PY{l+s+s1}{\PYZsq{}}\PY{p}{)} \PY{n}{fourth\PYZus{}pie} \PY{o}{=} \PY{n}{get\PYZus{}image}\PY{p}{(}\PY{n}{f}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{./data\PYZus{}runs/fourth/piecharts/}\PY{l+s+si}{\PYZob{}fname\PYZcb{}}\PY{l+s+s1}{\PYZsq{}}\PY{p}{)} \PY{n}{fifth\PYZus{}pie} \PY{o}{=} \PY{n}{get\PYZus{}image}\PY{p}{(}\PY{n}{f}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{./data\PYZus{}runs/fifth/piecharts/}\PY{l+s+si}{\PYZob{}fname\PYZcb{}}\PY{l+s+s1}{\PYZsq{}}\PY{p}{)} \PY{n}{first\PYZus{}peak} \PY{o}{=} \PY{n}{get\PYZus{}image}\PY{p}{(}\PY{n}{f}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{./data\PYZus{}runs/first/peaks/}\PY{l+s+si}{\PYZob{}fname\PYZcb{}}\PY{l+s+s1}{\PYZsq{}}\PY{p}{)} \PY{n}{second\PYZus{}peak} \PY{o}{=} \PY{n}{get\PYZus{}image}\PY{p}{(}\PY{n}{f}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{./data\PYZus{}runs/second/peaks/}\PY{l+s+si}{\PYZob{}fname\PYZcb{}}\PY{l+s+s1}{\PYZsq{}}\PY{p}{)} \PY{n}{third\PYZus{}peak} \PY{o}{=} \PY{n}{get\PYZus{}image}\PY{p}{(}\PY{n}{f}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{./data\PYZus{}runs/third/peaks/}\PY{l+s+si}{\PYZob{}fname\PYZcb{}}\PY{l+s+s1}{\PYZsq{}}\PY{p}{)} \PY{n}{fourth\PYZus{}peak} \PY{o}{=} \PY{n}{get\PYZus{}image}\PY{p}{(}\PY{n}{f}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{./data\PYZus{}runs/fourth/peaks/}\PY{l+s+si}{\PYZob{}fname\PYZcb{}}\PY{l+s+s1}{\PYZsq{}}\PY{p}{)} \PY{n}{fifth\PYZus{}peak} \PY{o}{=} \PY{n}{get\PYZus{}image}\PY{p}{(}\PY{n}{f}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{./data\PYZus{}runs/fifth/peaks/}\PY{l+s+si}{\PYZob{}fname\PYZcb{}}\PY{l+s+s1}{\PYZsq{}}\PY{p}{)} \PY{n}{pie\PYZus{}images} \PY{o}{=} \PY{p}{[}\PY{n}{first\PYZus{}pie}\PY{p}{,} \PY{n}{second\PYZus{}pie}\PY{p}{,} \PY{n}{third\PYZus{}pie}\PY{p}{,} \PY{n}{fourth\PYZus{}pie}\PY{p}{,} \PY{n}{fifth\PYZus{}pie}\PY{p}{]} \PY{n}{peak\PYZus{}images} \PY{o}{=} \PY{p}{[}\PY{n}{first\PYZus{}peak}\PY{p}{,} \PY{n}{second\PYZus{}peak}\PY{p}{,} \PY{n}{third\PYZus{}peak}\PY{p}{,} \PY{n}{fourth\PYZus{}peak}\PY{p}{,} \PY{n}{fifth\PYZus{}peak}\PY{p}{]} \PY{n}{fig}\PY{p}{,} \PY{n}{ax} \PY{o}{=} \PY{n}{plt}\PY{o}{.}\PY{n}{subplots}\PY{p}{(}\PY{p}{)} \PY{n}{implot} \PY{o}{=} \PY{n}{ax}\PY{o}{.}\PY{n}{imshow}\PY{p}{(}\PY{n}{image}\PY{p}{)} \PY{n}{plt}\PY{o}{.}\PY{n}{axis}\PY{p}{(}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{off}\PY{l+s+s1}{\PYZsq{}}\PY{p}{)} \PY{n}{plt}\PY{o}{.}\PY{n}{grid}\PY{p}{(}\PY{n}{b}\PY{o}{=}\PY{k+kc}{None}\PY{p}{)} \PY{n}{plt}\PY{o}{.}\PY{n}{figure}\PY{p}{(}\PY{n}{figsize}\PY{o}{=}\PY{p}{(}\PY{l+m+mi}{5}\PY{p}{,}\PY{l+m+mi}{5}\PY{p}{)}\PY{p}{,} \PY{n}{dpi}\PY{o}{=}\PY{l+m+mi}{199}\PY{p}{)} \PY{n}{plt}\PY{o}{.}\PY{n}{savefig}\PY{p}{(}\PY{n}{f}\PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{./nbimg/}\PY{l+s+si}{\PYZob{}filename\PYZcb{}}\PY{l+s+s2}{\PYZdq{}}\PY{p}{)} \PY{n}{plt}\PY{o}{.}\PY{n}{show}\PY{p}{(}\PY{p}{)} \PY{n}{plt}\PY{o}{.}\PY{n}{close}\PY{p}{(}\PY{p}{)} \PY{k}{for} \PY{n}{i} \PY{o+ow}{in} \PY{n+nb}{range}\PY{p}{(}\PY{n+nb}{len}\PY{p}{(}\PY{n}{pie\PYZus{}images}\PY{p}{)}\PY{p}{)}\PY{p}{:} \PY{n}{plt}\PY{o}{.}\PY{n}{subplot}\PY{p}{(}\PY{l+m+mi}{1}\PY{p}{,} \PY{n+nb}{len}\PY{p}{(}\PY{n}{pie\PYZus{}images}\PY{p}{)}\PY{p}{,} \PY{n}{i}\PY{o}{+}\PY{l+m+mi}{1}\PY{p}{)} \PY{n}{plt}\PY{o}{.}\PY{n}{axis}\PY{p}{(}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{off}\PY{l+s+s1}{\PYZsq{}}\PY{p}{)} \PY{n}{plt}\PY{o}{.}\PY{n}{grid}\PY{p}{(}\PY{n}{b}\PY{o}{=}\PY{k+kc}{None}\PY{p}{)} \PY{n}{plt}\PY{o}{.}\PY{n}{imshow}\PY{p}{(}\PY{n}{pie\PYZus{}images}\PY{p}{[}\PY{n}{i}\PY{p}{]}\PY{p}{)} \PY{n}{plt}\PY{o}{.}\PY{n}{figure}\PY{p}{(}\PY{n}{figsize}\PY{o}{=}\PY{p}{(}\PY{l+m+mi}{4}\PY{p}{,} \PY{l+m+mi}{10}\PY{p}{)}\PY{p}{,} \PY{n}{dpi}\PY{o}{=}\PY{l+m+mi}{199}\PY{p}{)} \PY{n}{plt}\PY{o}{.}\PY{n}{savefig}\PY{p}{(}\PY{n}{f}\PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{./nbimg/pie\PYZhy{}}\PY{l+s+si}{\PYZob{}fname\PYZcb{}}\PY{l+s+s2}{\PYZdq{}}\PY{p}{)} \PY{n}{plt}\PY{o}{.}\PY{n}{show}\PY{p}{(}\PY{p}{)} \PY{n}{plt}\PY{o}{.}\PY{n}{close}\PY{p}{(}\PY{p}{)} \PY{k}{for} \PY{n}{i} \PY{o+ow}{in} \PY{n+nb}{range}\PY{p}{(}\PY{n+nb}{len}\PY{p}{(}\PY{n}{peak\PYZus{}images}\PY{p}{)}\PY{p}{)}\PY{p}{:} \PY{n}{plt}\PY{o}{.}\PY{n}{subplot}\PY{p}{(}\PY{l+m+mi}{1}\PY{p}{,} \PY{n+nb}{len}\PY{p}{(}\PY{n}{peak\PYZus{}images}\PY{p}{)}\PY{p}{,} \PY{n}{i}\PY{o}{+}\PY{l+m+mi}{1}\PY{p}{)} \PY{n}{plt}\PY{o}{.}\PY{n}{axis}\PY{p}{(}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{off}\PY{l+s+s1}{\PYZsq{}}\PY{p}{)} \PY{n}{plt}\PY{o}{.}\PY{n}{grid}\PY{p}{(}\PY{n}{b}\PY{o}{=}\PY{k+kc}{None}\PY{p}{)} \PY{n}{plt}\PY{o}{.}\PY{n}{imshow}\PY{p}{(}\PY{n}{peak\PYZus{}images}\PY{p}{[}\PY{n}{i}\PY{p}{]}\PY{p}{)} \PY{n}{plt}\PY{o}{.}\PY{n}{figure}\PY{p}{(}\PY{n}{figsize}\PY{o}{=}\PY{p}{(}\PY{l+m+mi}{4}\PY{p}{,} \PY{l+m+mi}{10}\PY{p}{)}\PY{p}{,} \PY{n}{dpi}\PY{o}{=}\PY{l+m+mi}{199}\PY{p}{)} \PY{n}{plt}\PY{o}{.}\PY{n}{savefig}\PY{p}{(}\PY{n}{f}\PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{./nbimg/peak\PYZhy{}}\PY{l+s+si}{\PYZob{}fname\PYZcb{}}\PY{l+s+s2}{\PYZdq{}}\PY{p}{)} \PY{n}{plt}\PY{o}{.}\PY{n}{show}\PY{p}{(}\PY{p}{)} \PY{n}{plt}\PY{o}{.}\PY{n}{close}\PY{p}{(}\PY{p}{)} \end{Verbatim} \begin{landscape} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (1).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-0.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-0.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (10).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-1.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-1.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (100).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-2.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-2.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (101).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-3.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-3.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (102).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-4.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-4.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (103).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-5.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-5.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (104).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-6.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-6.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (105).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-7.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-7.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (106).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-8.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-8.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (107).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-9.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-9.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (108).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-10.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-10.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (109).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-11.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-11.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (11).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-12.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-12.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (110).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-13.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-13.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (111).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-14.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-14.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (112).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-15.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-15.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (113).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-16.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-16.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (114).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-17.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-17.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (115).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-18.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-18.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (116).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-19.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-19.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (117).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-20.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-20.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (118).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-21.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-21.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (119).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-22.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-22.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (12).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-23.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-23.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (120).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-24.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-24.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (121).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-25.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-25.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (122).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-26.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-26.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (123).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-27.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-27.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (124).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-28.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-28.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (125).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-29.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-29.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (126).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-30.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-30.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (127).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-31.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-31.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (128).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-32.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-32.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (129).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-33.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-33.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (13).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-34.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-34.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (130).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-35.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-35.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (131).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-36.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-36.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (132).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-37.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-37.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (133).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-38.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-38.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (134).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-39.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-39.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (135).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-40.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-40.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (136).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-41.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-41.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (137).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-42.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-42.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (138).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-43.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-43.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (139).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-44.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-44.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (14).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-45.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-45.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (140).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-46.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-46.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (141).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-47.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-47.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (142).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-48.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-48.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (143).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-49.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-49.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (144).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-50.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-50.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (145).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-51.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-51.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (146).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-52.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-52.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (147).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-53.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-53.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (148).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-54.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-54.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (149).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-55.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-55.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (15).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-56.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-56.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (150).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-57.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-57.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (151).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-58.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-58.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (152).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-59.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-59.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (153).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-60.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-60.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (154).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-61.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-61.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (155).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-62.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-62.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (156).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-63.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-63.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (157).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-64.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-64.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (158).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-65.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-65.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (159).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-66.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-66.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (16).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-67.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-67.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (160).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-68.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-68.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (161).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-69.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-69.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (162).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-70.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-70.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (163).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-71.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-71.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (164).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-72.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-72.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (165).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-73.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-73.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (166).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-74.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-74.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (167).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-75.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-75.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (168).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-76.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-76.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (169).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-77.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-77.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (17).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-78.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-78.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (170).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-79.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-79.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (171).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-80.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-80.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (172).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-81.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-81.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (173).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-82.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-82.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (174).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-83.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-83.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (175).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-84.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-84.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (176).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-85.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-85.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (177).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-86.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-86.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (178).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-87.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-87.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (179).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-88.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-88.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (18).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-89.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-89.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (180).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-90.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-90.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (181).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-91.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-91.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (182).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-92.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-92.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (183).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-93.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-93.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (184).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-94.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-94.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (185).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-95.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-95.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (186).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-96.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-96.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (187).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-97.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-97.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (188).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-98.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-98.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (189).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-99.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-99.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (19).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-100.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-100.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (190).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-101.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-101.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (191).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-102.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-102.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (192).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-103.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-103.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (193).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-104.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-104.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (194).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-105.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-105.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (195).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-106.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-106.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (196).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-107.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-107.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (197).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-108.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-108.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (198).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-109.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-109.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (199).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-110.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-110.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (2).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-111.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-111.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (20).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-112.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-112.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (200).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-113.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-113.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (201).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-114.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-114.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (202).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-115.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-115.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (203).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-116.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-116.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (204).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-117.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-117.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (205).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-118.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-118.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (206).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-119.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-119.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (207).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-120.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-120.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (208).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-121.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-121.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (209).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-122.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-122.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (21).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-123.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-123.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (210).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-124.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-124.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (211).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-125.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-125.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (212).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-126.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-126.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (213).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-127.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-127.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (214).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-128.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-128.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (215).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-129.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-129.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (216).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-130.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-130.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (217).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-131.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-131.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (218).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-132.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-132.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (219).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-133.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-133.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (22).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-134.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-134.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (220).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-135.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-135.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (221).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-136.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-136.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (222).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-137.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-137.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (223).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-138.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-138.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (224).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-139.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-139.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (225).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-140.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-140.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (226).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-141.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-141.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (227).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-142.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-142.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (228).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-143.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-143.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (229).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-144.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-144.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (23).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-145.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-145.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (230).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-146.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-146.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (231).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-147.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-147.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (232).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-148.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-148.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (233).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-149.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-149.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (234).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-150.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-150.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (235).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-151.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-151.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (236).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-152.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-152.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (237).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-153.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-153.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (238).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-154.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-154.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (239).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-155.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-155.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (24).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-156.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-156.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (240).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-157.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-157.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (241).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-158.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-158.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (242).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-159.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-159.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (243).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-160.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-160.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (244).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-161.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-161.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (245).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-162.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-162.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (246).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-163.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-163.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (247).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-164.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-164.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (248).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-165.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-165.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (249).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-166.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-166.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (25).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-167.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-167.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (250).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-168.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-168.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (251).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-169.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-169.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (252).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-170.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-170.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (253).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-171.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-171.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (254).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-172.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-172.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (255).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-173.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-173.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (256).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-174.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-174.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (257).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-175.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-175.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (258).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-176.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-176.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (259).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-177.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-177.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (26).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-178.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-178.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (260).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-179.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-179.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (261).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-180.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-180.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (262).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-181.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-181.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (263).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-182.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-182.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (264).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-183.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-183.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (265).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-184.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-184.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (266).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-185.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-185.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (267).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-186.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-186.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (268).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-187.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-187.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (269).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-188.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-188.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (27).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-189.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-189.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (270).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-190.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-190.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (271).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-191.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-191.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (272).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-192.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-192.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (273).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-193.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-193.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (274).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-194.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-194.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (275).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-195.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-195.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (276).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-196.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-196.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (277).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-197.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-197.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (278).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-198.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-198.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (279).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-199.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-199.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (28).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-200.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-200.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (280).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-201.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-201.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (281).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-202.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-202.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (282).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-203.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-203.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (283).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-204.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-204.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (284).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-205.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-205.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (285).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-206.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-206.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (286).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-207.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-207.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (287).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-208.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-208.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (288).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-209.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-209.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (289).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-210.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-210.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (29).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-211.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-211.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (290).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-212.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-212.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (291).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-213.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-213.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (292).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-214.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-214.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (293).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-215.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-215.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (294).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-216.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-216.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (295).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-217.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-217.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (296).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-218.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-218.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (297).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-219.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-219.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (298).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-220.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-220.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (299).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-221.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-221.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (3).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-222.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-222.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (30).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-223.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-223.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (300).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-224.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-224.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (301).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-225.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-225.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (302).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-226.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-226.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (303).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-227.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-227.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (304).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-228.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-228.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (305).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-229.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-229.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (306).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-230.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-230.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (307).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-231.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-231.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (308).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-232.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-232.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (309).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-233.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-233.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (31).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-234.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-234.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (310).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-235.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-235.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (311).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-236.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-236.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (312).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-237.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-237.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (313).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-238.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-238.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (314).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-239.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-239.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (315).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-240.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-240.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (316).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-241.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-241.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (317).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-242.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-242.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (318).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-243.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-243.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (319).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-244.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-244.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (32).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-245.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-245.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (320).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-246.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-246.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (321).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-247.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-247.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (322).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-248.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-248.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (323).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-249.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-249.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (324).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-250.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-250.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (325).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-251.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-251.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (326).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-252.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-252.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (327).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-253.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-253.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (328).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-254.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-254.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (329).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-255.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-255.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (33).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-256.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-256.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (330).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-257.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-257.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (331).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-258.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-258.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (332).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-259.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-259.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (333).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-260.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-260.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (334).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-261.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-261.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (335).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-262.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-262.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (336).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-263.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-263.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (337).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-264.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-264.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (338).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-265.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-265.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (339).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-266.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-266.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (34).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-267.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-267.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (340).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-268.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-268.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (341).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-269.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-269.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (342).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-270.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-270.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (343).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-271.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-271.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (344).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-272.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-272.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (345).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-273.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-273.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (346).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-274.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-274.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (347).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-275.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-275.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (348).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-276.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-276.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (349).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-277.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-277.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (35).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-278.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-278.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (350).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-279.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-279.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (351).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-280.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-280.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (352).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-281.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-281.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (353).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-282.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-282.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (354).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-283.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-283.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (355).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-284.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-284.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (356).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-285.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-285.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (357).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-286.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-286.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (358).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-287.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-287.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (359).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-288.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-288.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (36).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-289.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-289.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (360).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-290.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-290.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (361).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-291.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-291.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (362).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-292.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-292.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (363).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-293.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-293.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (364).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-294.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-294.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (365).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-295.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-295.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (366).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-296.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-296.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (367).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-297.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-297.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (368).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-298.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-298.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (369).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-299.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-299.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (37).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-300.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-300.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (370).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-301.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-301.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (371).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-302.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-302.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (372).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-303.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-303.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (373).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-304.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-304.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (374).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-305.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-305.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (375).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-306.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-306.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (376).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-307.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-307.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (377).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-308.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-308.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (378).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-309.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-309.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (379).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-310.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-310.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (38).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-311.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-311.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (380).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-312.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-312.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (381).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-313.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-313.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (382).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-314.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-314.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (383).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-315.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-315.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (384).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-316.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-316.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (385).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-317.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-317.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (386).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-318.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-318.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (387).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-319.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-319.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (388).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-320.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-320.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (389).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-321.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-321.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (39).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-322.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-322.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (390).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-323.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-323.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (391).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-324.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-324.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (392).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-325.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-325.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (393).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-326.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-326.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (394).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-327.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-327.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (395).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-328.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-328.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (396).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-329.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-329.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (397).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-330.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-330.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (398).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-331.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-331.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (399).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-332.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-332.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (4).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-333.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-333.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (40).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-334.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-334.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (400).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-335.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-335.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (401).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-336.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-336.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (402).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-337.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-337.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (403).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-338.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-338.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (404).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-339.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-339.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (405).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-340.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-340.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (406).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-341.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-341.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (407).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-342.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-342.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (408).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-343.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-343.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (409).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-344.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-344.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (41).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-345.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-345.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (410).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-346.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-346.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (411).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-347.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-347.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (412).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-348.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-348.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (413).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-349.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-349.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (414).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-350.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-350.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (415).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-351.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-351.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (416).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-352.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-352.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (417).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-353.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-353.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (418).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-354.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-354.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (419).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-355.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-355.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (42).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-356.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-356.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (420).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-357.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-357.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (421).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-358.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-358.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (422).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-359.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-359.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (423).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-360.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-360.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (424).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-361.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-361.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (425).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-362.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-362.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (426).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-363.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-363.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (427).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-364.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-364.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (428).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-365.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-365.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (429).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-366.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-366.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (43).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-367.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-367.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (430).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-368.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-368.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (431).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-369.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-369.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (432).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-370.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-370.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (433).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-371.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-371.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (434).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-372.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-372.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (435).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-373.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-373.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (436).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-374.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-374.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (437).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-375.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-375.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (438).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-376.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-376.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (439).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-377.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-377.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (44).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-378.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-378.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (440).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-379.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-379.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (441).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-380.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-380.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (442).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-381.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-381.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (443).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-382.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-382.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (444).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-383.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-383.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (445).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-384.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-384.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (446).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-385.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-385.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (447).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-386.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-386.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (448).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-387.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-387.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (449).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-388.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-388.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (45).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-389.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-389.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (450).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-390.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-390.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (451).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-391.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-391.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (46).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-392.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-392.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (47).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-393.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-393.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (48).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-394.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-394.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (49).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-395.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-395.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (5).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-396.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-396.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (50).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-397.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-397.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (51).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-398.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-398.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (52).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-399.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-399.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (53).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-400.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-400.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (54).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-401.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-401.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (55).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-402.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-402.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (56).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-403.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-403.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (57).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-404.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-404.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (58).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-405.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-405.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (59).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-406.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-406.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (6).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-407.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-407.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (60).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-408.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-408.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (61).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-409.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-409.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (62).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-410.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-410.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (63).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-411.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-411.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (64).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-412.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-412.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (65).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-413.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-413.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (66).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-414.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-414.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (67).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-415.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-415.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (68).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-416.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-416.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (69).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-417.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-417.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (7).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-418.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-418.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (70).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-419.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-419.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (71).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-420.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-420.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (72).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-421.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-421.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (73).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-422.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-422.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (74).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-423.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-423.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (75).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-424.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-424.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (76).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-425.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-425.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (77).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-426.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-426.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (78).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-427.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-427.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (79).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-428.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-428.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (8).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-429.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-429.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (80).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-430.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-430.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (81).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-431.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-431.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (82).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-432.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-432.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (83).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-433.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-433.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (84).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-434.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-434.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (85).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-435.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-435.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (86).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-436.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-436.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (87).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-437.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-437.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (88).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-438.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-438.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (89).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-439.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-439.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (9).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-440.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-440.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (90).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-441.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-441.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (91).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-442.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-442.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (92).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-443.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-443.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (93).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-444.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-444.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (94).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-445.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-445.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (95).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-446.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-446.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (96).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-447.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-447.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (97).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-448.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-448.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (98).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-449.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-449.jpg} \end{center} \begin{center} \includegraphics[width=\textwidth]{./nbimg/file (99).jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/pie-450.jpg} \end{center} \begin{center} \includegraphics[width=250mm]{./nbimg/peak-450.jpg} \end{center} \end{landscape} % Add a bibliography block to the postdoc \end{document}
\documentclass{article} \usepackage[utf8]{inputenc} \title{PS3 Buchman} \author{blakebuchman03 } \date{February 2021} \usepackage{natbib} \usepackage{graphicx} \begin{document} \maketitle \section{Questions} 1. How big was the insurance .csv file once compressed? \newline 5MB \newline \newline 2. How many lines did the CSV file have before doing the end-of-line (EOL) conversion? \newline 0 \newline \newline 3. How many lines did the CSV file have after doing the EOL conversion? \newline 36,634 \end{document}
\chapter{Here is a nice little table} \begin{tabular}{c c c c} \hline Operation Name & Code & Cost & \\ \hline Add a new item & \texttt{A.add(newitem)} & $1$ & \\ Delete an item & \texttt{A.delete(item)} & $1$ & \\ Union & \texttt{A | B} & $n_A + n_B$ & \\ Intersection & \texttt{A \& B} & $\min{n_A, n_B}$ & \\ Set differences & \texttt{A - B} & $n_A$ & \\ Symmetric Difference & \texttt{A \wedge B} & $n_A + n_B$ & \\ \hline \end{tabular} \begin{Verbatim}[commandchars=\\\{\}] \PY{k+kn}{import} \PY{n+nn}{markdown} \PY{k}{def} \PY{n+nf}{escape}\PY{p}{(}\PY{n}{txt}\PY{p}{)}\PY{p}{:} \PY{l+s+sd}{\PYZdq{}\PYZdq{}\PYZdq{} basic html escaping \PYZdq{}\PYZdq{}\PYZdq{}} \PY{n}{txt} \PY{o}{=} \PY{n}{txt}\PY{o}{.}\PY{n}{replace}\PY{p}{(}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{\PYZam{}}\PY{l+s+s1}{\PYZsq{}}\PY{p}{,} \PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{\PYZam{}amp;}\PY{l+s+s1}{\PYZsq{}}\PY{p}{)} \PY{n}{txt} \PY{o}{=} \PY{n}{txt}\PY{o}{.}\PY{n}{replace}\PY{p}{(}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{\PYZlt{}}\PY{l+s+s1}{\PYZsq{}}\PY{p}{,} \PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{\PYZam{}lt;}\PY{l+s+s1}{\PYZsq{}}\PY{p}{)} \PY{n}{txt} \PY{o}{=} \PY{n}{txt}\PY{o}{.}\PY{n}{replace}\PY{p}{(}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{\PYZgt{}}\PY{l+s+s1}{\PYZsq{}}\PY{p}{,} \PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{\PYZam{}gt;}\PY{l+s+s1}{\PYZsq{}}\PY{p}{)} \PY{n}{txt} \PY{o}{=} \PY{n}{txt}\PY{o}{.}\PY{n}{replace}\PY{p}{(}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{\PYZdq{}}\PY{l+s+s1}{\PYZsq{}}\PY{p}{,} \PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{\PYZam{}quot;}\PY{l+s+s1}{\PYZsq{}}\PY{p}{)} \PY{k}{return} \PY{n}{txt} \PY{n}{tbl} \PY{o}{=} \PY{l+s+s2}{\PYZdq{}\PYZdq{}\PYZdq{}} \PY{l+s+s2}{First Header | Second Header} \PY{l+s+s2}{\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{} | \PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}} \PY{l+s+s2}{Content Cell | Content Cell} \PY{l+s+s2}{Content Cell | Content Cell} \PY{l+s+s2}{\PYZdq{}\PYZdq{}\PYZdq{}} \PY{n}{html} \PY{o}{=} \PY{n}{markdown}\PY{o}{.}\PY{n}{markdown}\PY{p}{(}\PY{n}{tbl}\PY{p}{,} \PY{n}{extensions}\PY{o}{=}\PY{p}{[}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{tables}\PY{l+s+s1}{\PYZsq{}}\PY{p}{]}\PY{p}{)} \PY{n+nb}{print}\PY{p}{(}\PY{n}{escape}\PY{p}{(}\PY{n}{html}\PY{p}{)}\PY{p}{)} \end{Verbatim} \begin{Verbatim} <table> <thead> <tr> <th>First Header</th> <th>Second Header</th> </tr> </thead> <tbody> <tr> <td>Content Cell</td> <td>Content Cell</td> </tr> <tr> <td>Content Cell</td> <td>Content Cell</td> </tr> </tbody> </table> \end{Verbatim} The goal is to transform this into the following. \texttt{\begin{tabular}{c c} \hline First Header \& Second Header \\ \hline Content Cell \& Content Cell \\ Content Cell \& Content Cell \\ \hline \end{tabular} }
\chapter{Introduction to Spreadsheets} For many real-world problems, spreadsheets are the perfect tool. In this chapter, you will be introduced to how to use a spreadsheet. There are numerous spreadsheet programs: Google Sheets, Microsoft Excel, Apple Numbers, OpenOffice Calc, etc. All of them are very similar. I will be using Google Sheets, but if you are using one of the others, you should be able to follow along. The first spreadsheet program (VisiCalc) was introduced in 1979 as a tool for finance people to play ``what if'' games. For example, a company might make a spreadsheet that told them how much more profit they would make if they changed from using an expensive metal to using a cheaper alloy.\index{Spreadsheet} In honor of its history, let's start by studying a business question: I have a friend who dreams of quitting her job to become a cooper. (A cooper makes barrels that are used for aging wine and whiskey.) She says: \begin{itemize} \item It costs \$45 dollars in materials to build one barrel. \item A barrel sells for \$100 dollars. \item The workshop/warehouse she wants to rent costs \$2000 per month. \item Taxes would take about 20\% of her profits \item She needs to make \$4000 after taxes to live \end{itemize} She has asked you, ``How many barrels do I need to make each month to survive?'' \section{Solving It Symbolically} Many problems can be solved two ways: symbolically or numerically.\index{symbolic vs. numeric solutions} To solve this problem symbolically, you would write out the facts as equations or inequalities and then do symbol manipulations until you ended up with an answer. In this case, you would let $b$ be the number of barrells and create the following inequality: $$(1.0 - 0.2)\left(b(100 - 45) - 2000\right) \geq 4000$$ You would simplify it: $$(0.8)\left(55 b - 2000\right) \geq 4000$$ And simplify it more: $$44b - 1600 \geq 4000$$ If that is true, then: $$44b \geq 5600$$ And if that is true, then: $$b \geq \frac{1400}{11}$$ $1400/11$ is about 127.27, so she needs to make and sell 128 barrels each month. That is a perfect answer, and we didn't need a spreadsheet at all. Two things: \begin{itemize} \item As problems get larger and more realistic, it gets much more difficult to solve them symbolically. \item As soon as you say ``Yes, you need to make and sell 128 barrels each month.'' Your friend will ask ``What if I make and sell 200 barrels? How much money will I make then?'' \end{itemize} So we will use a spreadsheet to solve the problem numerically. \section{Solving It Numerically (with a spreadsheet)} Let's get back to our example. Put labels in the A column: \begin{itemize} \item{Barrels produced (per month)} \item{Materials cost (per barrel)} \item{Sale price (per barrel)} \item{Pre-tax earnings (per month)} \item{Taxes (per month)} \item{Take home pay (per month)} \end{itemize} Format them any way you like. It should look something like this: \includegraphics[width=0.4\textwidth]{BarrelLabels.png} In the B column, the first four cells are values (not formulas): \begin{itemize} \item{115 formatted as a number with no decimal point} \item{45 formatted as currency} \item{100 formatted as currency} \item{2000 formatted as currency} \end{itemize} It should look something like this: \includegraphics[width=0.5\textwidth]{BarrelValues.png} The next three cells in the B column will have formulas: \begin{itemize} \item{B1 * (B3 - B2) - B4} \item{0.2 * B5} \item{B5 - B6} \end{itemize} It should look something like this: \includegraphics[width=0.5\textwidth]{BarrelFormulas.png} Now you can share this spreadsheet with your friend and she can put different values into the cells for what-if games. Like ``If I can get my materials cost down to \$42 per barrel, what happens to my take home pay?'' Sometimes it is nice to show a range of values for a variable or two. In this case, it might be nice to show your friend what the numbers look like if she produces 115, 120, 125, 130, 135, or 140 barrels per month. We have one column, and now we need six. How do we duplicate cells? \begin{enumerate} \item Click B1 to select it and then shift click on B7 to select all seven cells. \item Copy them. (There is probably a menu item for this.) \item Click C1 to select it \item Paste them. \end{enumerate} \includegraphics[width=0.5\textwidth]{BarrelCopyPaste.png} We want the first cell in the new column to be 120. You could just type in 120, but lets do something more clever. Put a formula into that cell: = B1 + 5. Now the cell should show 120. Why did we put in a formula? When we duplicate this column, this cell will always have 5 more barrels than the cell to its left. Now lets duplicate the second column a few times. The easy way to do this is to select the cells as you did before and drag the lower-right corner to the right until column G is in the selection. When you end the drag, the copies will appear: \includegraphics[width=0.8\textwidth]{BarrelDragPaste.png} Nice, right? Now your friend can easily see how many barrels corresponds to how much take-home pay. You know what she really wants? A graph. \section{Graphing} Graphing is a little different on every different platform. Here is what you want the graph to look like. \includegraphics[width=0.8\textwidth]{BarrelGraph.png} On Google Sheets:\index{spreadsheet!graphs} \begin{enumerate} \item Select cells B7 through G7. \item Choose the menu item Insert -> Chart. \item Choose the chart type (Line) \item Add the X-axis to be B1 through G1. \item Under the Customize tab, Set the label for the X-axis to be ``Barrels Made and Sold''. \item Delete the chart title (which is the same as the Y-axis label). \end{enumerate} \section{Other Things You Should Know About Spreadsheets} Your spreadsheet document can have several ``Sheets''. Each has its own grid of cells. The sheet has a name; usually you call it something like ``Salaries''. When you need to use a value from the ``Salaries'' sheet in another sheet, you can specify ``Salaries!A2'' -- that is, cell A2 on sheet ``Salaries''. To flip between the sheets there is usually a tab for each at the bottom of the document. \includegraphics[width=0.5\textwidth]{Sheets.png} By default, the cell references are relative. That is, when you write a formula in cell H5 that references the value in cell G4, the cell remembers ``The cell that is one up and one to the left of me.'' Thus, if you copy that formula into B9, now that formula reads the value from A8. If you want an absolute reference, you use \$. If H5 references \$G\$4, G4 will be used no matter where on the sheet the formula is copied to. You can use the \$ on the row or colum. In \$A4, the column is absolute and the row is relative. In A\$4, the row is absolute and the column is relative. \section{Challenge: Make a spreadsheet} You have a company that bids on painting jobs. Make a spreadsheet to help you do bids. Here are the parameters: \begin{itemize} \item The client will tell you how many square meters of wall need to be painted. \item Paint costs \$0.02 per square meter of wall to cover \item On average, a square meter of wall takes 0.02 hours to paint. \item You can hire painters at \$15 per hour. \item You add 20\% to your estimated costs for a margin of error and profit. \end{itemize} Make a spreadsheet such that when you type in the square meters to be painted, the spreadsheet tells you how much you will spend on paint and labor. It also tells you what your bid should be.
\chapter{AHTR Optimization Preliminary Work} \label{chap:rollo-demo} This chapter demonstrates the preliminary work completed for \gls{AHTR} optimization. I used \gls{ROLLO} to apply genetic algorithms to maximize $k_{eff}$ in a single \gls{AHTR} fuel slab. Then, I presented spatial and energy homogenizations for applications to \gls{AHTR} multiphysics simulations. The \texttt{dissertation-results} Github repository contains all the scripts, results, and plots shown in this chapter \cite{chee_dissertation_2021}. \section{ROLLO Optimization: AHTR Fuel Slab} \label{sec:rollo_opt_ahtr_slab} This demonstration problem explores how heterogenous fuel distributions impact $k_{eff}$ compared with homogenous fuel distributions customary in most reactor designs. I use OpenMC v0.12.0 \cite{romano_openmc_2013} for these neutronics calculations with the ENDF/B-VII.1 data library \cite{chadwick_endf/b-vii.1_2011}. \subsection{Problem Definition} The reactor core explored is a single fuel slab from the \gls{FHR} benchmark \gls{AHTR} design. I modified the fuel slab to be straightened with perpendicular sides, instead of slanted as in Figure \ref{fig:ahtr-fuel-plank}. Figure \ref{fig:straightened_slab} illustrates the straightened fuel slab with periodic boundary conditions in the x-y axis. The periodic surfaces are: 1-3, 2-4. \begin{figure}[] \centering \includegraphics[width=0.85\linewidth]{straightened_slab.png} \begin{tikzpicture} \draw[ thick,-latex] (0,0) -- (1,0) node[anchor=south west] {$x$}; \draw[ thick,-latex] (0,0) -- (0,1) node[anchor=south west] {$y$}; \draw[ thick,-latex] (0,0) -- (1,1) node[anchor=south west] {$z$}; \tkzText[above](-0.3,-0.7){} \end{tikzpicture} \raggedright \resizebox{0.3\textwidth}{!}{ \hspace{1cm} \fbox{\begin{tabular}{ll} \textcolor{fhrblue}{$\blacksquare$} & FLiBe \\ \textcolor{fhrgrey}{$\blacksquare$} & Graphite (Fuel Plank)\\ \textcolor{fhrred}{$\blacksquare$} & Graphite (Fuel Stripe) \\ \textcolor{fhrblack}{$\blacksquare$} & TRISO particle \end{tabular}}} \caption{Straightened \acrfull{AHTR} fuel slab, with x-y periodic surfaces: 1-3, 2-4, and reflective z-axis surfaces (out of the page). Original slanted fuel slabs can be seen in Figures \ref{fig:ahtr-fuel-assembly} and \ref{fig:ahtr-fuel-plank}.} \label{fig:straightened_slab} \end{figure} The slab has $27.1 \times 3.25 \times 1.85\ cm^3$ dimensions with reflective top and bottom (along z-axis) boundary conditions. I use the same materials as in the \gls{FHR} benchmark, except that I homogenized each \gls{TRISO} particle's four outer layers: porous carbon buffer, inner pyrolytic carbon, silicon carbide layer, and the outer pyrolytic carbon. The \gls{TRISO} particle dimensions remain the same. Table \ref{tab:keff_triso} reports the $k_{eff}$ for this original straightened \gls{AHTR} configuration with and without the outer layer \gls{TRISO} homogenization. \begin{table}[] \centering \onehalfspacing \caption{Straightened \acrfull{AHTR} fuel slab $k_{eff}$ for case with no \gls{TRISO} homogenization and case with homogenization of the four outer layers. Both simulations were run on one BlueWaters XE Node.} \label{tab:keff_triso} \footnotesize \begin{tabular}{llc} \hline \textbf{TRISO Homogenization}& \textbf{$k_{eff}$} & \textbf{Simulation time [s]} \\ \hline None & $1.38548 \pm 0.00124$ & 233\\ Four outer layers & $1.38625 \pm 0.00109$ & 168\\ \hline \end{tabular} \end{table} The \gls{TRISO} particle outer four-layer homogenization resulted in a $30\%$ speed-up without compromising accuracy with $k_{eff}$ values within each other's uncertainty. The \gls{ROLLO} optimization objective aims to maximize the slab $k_{eff}$. It does so by varying the \gls{TRISO} particle packing fraction across the slab while keeping the total packing fraction constant at 0.0979. This total packing fraction is consistent with the original straightened slab with TRISO particles in fuel stripes (Figure \ref{fig:straightened_slab}). I divided the slab into ten cells along the x-axis between the \gls{FLiBe} and graphite buffers, resulting in ten $2.31 \times 2.55 \times 1.85\ cm^3$ cells. A sine distribution governs the \gls{TRISO} particle packing fraction's distribution across cells: \begin{align} PF(x) &= \left(a\cdot sin(b\cdot x + c) + 2\right) \cdot NF\\ \intertext{where} PF &= \mbox{packing fraction } [-] \nonumber \\ a &= \mbox{amplitude, peak deviation of the function from zero } [-] \nonumber \\ b &= \mbox{angular frequency, rate of change of the function argument } [\frac{radians}{cm}] \nonumber \\ c &= \mbox{phase, the position in its cycle the oscillation is at t = 0 } [radians]\nonumber \\ x &= \mbox{midpoint value for each cell } [cm]\nonumber \\ NF &= \mbox{Normalization factor } [-]\nonumber \end{align} The normalization factor ensures a consistent total packing fraction in the slab regardless the \gls{TRISO} particle distribution. For example, a packing fraction distribution of $PF(x) = \left(0.5\cdot sin(\frac{\pi}{3}\cdot x + \pi) + 2\right) \cdot NF$, results in the following packing fractions for the ten cells: 0.103, 0.120, 0.049, 0.138, 0.076, 0.081, 0.136, 0.048, 0.125, and 0.098. Figure \ref{fig:triso_distribution} shows this sine distribution, highlights the packing fraction at the respective midpoints, and displays the slab's x-y axis view with packing fraction varying based on this sine distribution. \begin{figure}[] \centering \makebox[\textwidth][c]{\includegraphics[width=1.1\linewidth]{triso_distribution_sine.png}} \caption{Above: Straightened \acrfull{AHTR} fuel slab with varying \gls{TRISO} particle distribution across ten cells based on the sine distribution. Below: $PF(x) = (0.5\ sin(\frac{\pi}{3}x + \pi) + 2) \times NF$ sine distribution with red points indicating the packing fraction at each cell. } \label{fig:triso_distribution} \end{figure} In \gls{ROLLO}, a genetic algorithm varies the $a$, $b$, and $c$ variables to find a combination that produces a packing fraction distribution that maximizes the slab's $k_{eff}$. I defined $a$, $b$, and $c$'s upper and lower bounds as: \begin{align*} 0 <\ &a < 2 \\ 0 <\ &b < \frac{\pi}{2} \\ 0 <\ &c < 2 \pi \end{align*} The bounds of $a$ keep the sine distribution from falling below zero. The $b$ and $c$ variable bounds spread wide enough to allow the genetic algorithm to explore various sine distributions. The OpenMC evaluator calculates $k_{eff}$. OpenMC runs each simulation with 80 active cycles, 20 inactive cycles, and 8000 particles to reach $\sim$130pcm uncertainty. Figure \ref{fig:rollo-input-simple} shows the \gls{ROLLO} input file for this genetic algorithm optimization problem. \texttt{ahtr\_slab\_openmc.py} is the template OpenMC straightened \gls{AHTR} slab script that accepts $a$, $b$ and $c$ from \gls{ROLLO}, calculates packing fraction distribution, and assigns packing fraction values to each fuel cell. Subsequently, \gls{ROLLO} runs the templated OpenMC script to generate $k_{eff}$. \begin{figure}[] \begin{minted}[ frame=lines, framesep=2mm, baselinestretch=1.2, fontsize=\footnotesize, linenos ]{json} { "control_variables": { "a": {"min": 0.0, "max": 2.0}, "b": {"min": 0.0, "max": 1.57}, "c": {"min": 0.0, "max": 6.28}, }, "evaluators": { "openmc": { "input_script": "ahtr_slab_openmc.py", "inputs": ["a", "b", "c"], "outputs": ["keff"], "keep_files": false, } }, "constraints": {"keff": {"operator": [">="], "constrained_val": [1.0]}}, "algorithm": { "objective": "max", "optimized_variable": "keff", "pop_size": 60, "generations": 10, "mutation_probability": 0.23, "mating_probability": 0.46, "selection_operator": {"operator": "selTournament", "inds": 15, "tournsize": 5}, "mutation_operator": { "operator": "mutPolynomialBounded", "eta": 0.23, "indpb": 0.23, }, "mating_operator": {"operator": "cxBlend", "alpha": 0.46}, }, } \end{minted} \caption{\acrfull{ROLLO} JSON input file to maximize $k_{eff}$ in the straightened \acrfull{AHTR} fuel slab by varying packing fraction distribution with control variables $a$, $b$, and $c$.} \label{fig:rollo-input-simple} \end{figure} \subsection{Hyperparameter Search} \label{sec:hyperparameter_search} In a \gls{ROLLO} input file, the user defines hyperparameters for the genetic algorithm. A good hyperparameter set guides the optimization process by balancing exploitation and exploration to find an optimal solution quickly and accurately. Finding a good hyperparameter set requires a trial-and-error process. I performed the hyperparameter search with a coarse-to-fine random sampling scheme, whose advantages I previously discussed in Section \ref{sec:balance}. The hyperparameters varied included population size, number of generations, mutation probability, mating probability, selection operator, selection operator's number of individuals, selection operator's tournament size, mutation operator, and mating operator. I started with 25 coarse experiments and fine-tuned the hyperparameters with 15 more experiments. For each genetic algorithm experiment, the number of OpenMC evaluations remained constant at 600. The number of evaluations correlated the population size and number of generations. I randomly sampled population size and used the following equation to calculate the number of generations: \begin{align} \mbox{no. of generations} &= \frac{\mbox{no. of evaluations}}{\mbox{population size} } \end{align} Table \ref{tab:hyperparameter_search} shows the lower and upper bounds used for randomly sampling each hyperparameter. \begin{table}[] \centering \onehalfspacing \caption{Hyperparameter search is conducted in three phases: \textit{Coarse Search}, \textit{Fine Search 1}, \textit{Fine Search 2}. Each hyperparameter's lower and upper bounds for each search phase are listed.} \label{tab:hyperparameter_search} \footnotesize \makebox[\textwidth][c]{\begin{tabular}{p{4cm}lp{3.4cm}p{3.4cm}p{3.4cm}} \hline \textbf{Hyperparameter}& \textbf{Type} & \textbf{Coarse Search Bounds} & \textbf{Fine Search 1 Bounds} & \textbf{Fine Search 2 Bounds} \\ \hline Experiments & - & 0 to 24 & 24 to 34 & 35 to 39 \\ \hline Population size (pop) & Continuous & 10 $<$ x $<$ 100 & 20 $<$ x $<$ 60 & 60 \\ Mutation probability & Continuous & 0.1 $<$ x $<$ 0.4 & 0.2 $<$ x $<$ 0.4& 0.2 $<$ x $<$ 0.3\\ Mating probability & Continuous & 0.1 $<$ x $<$ 0.6 & 0.1 $<$ x $<$ 0.3 & 0.45 $<$ x $<$ 0.6\\ Selection operator & Discrete & \texttt{SelTournament}, \texttt{SelBest}, \texttt{SelNSGA2} & \texttt{SelTournament}, \texttt{SelBest}, \texttt{SelNSGA2}& \texttt{SelTournament}\\ Selection individuals & Continuous & $\frac{1}{3}pop$ $<$ x $<$ $\frac{2}{3}pop$ & $\frac{1}{3}pop$ $<$ x $<$ $\frac{2}{3}pop$ & 15\\ Selection tournament size (only for SelTournament) & Continuous & 2 $<$ x $<$ 8 &2 $<$ x $<$ 8&5\\ Mutation operator & Discrete & \texttt{mutPolynomialBounded} &\texttt{mutPolynomialBounded}&\texttt{mutPolynomialBounded}\\ Mating operator & Discrete& \texttt{cxOnePoint}, \texttt{cxUniform}, \texttt{cxBlend} &\texttt{cxOnePoint}, \texttt{cxUniform}, \texttt{cxBlend}&\texttt{cxOnePoint}, \texttt{cxBlend}\\ \hline \end{tabular}} \end{table} The initial 25 coarse experiments' sought to narrow down the hyperparameters to find a smaller set of hyperparameter bounds that produce higher $k_{eff}$ values. Figure \ref{fig:hyperparameter_sens} shows the hyperparameters' plotted against each other with a third color dimension representing the average $k_{eff}$ value ($\overline{k_{eff}}$) in each experiment's final generation. Lighter scatter points indicate higher final population $\overline{k_{eff}}$ values, which suggests better hyperparameter sets. \begin{figure}[] \centering \makebox[\textwidth][c]{\includegraphics[width=1.3\linewidth]{hyperparameter_sens.png}} \caption{Coarse hyperparameters search's results. Hyperparameter values are plotted against each other with a third color dimension representing each experiment's final population's $\overline{k_{eff}}$.} \label{fig:hyperparameter_sens} \end{figure} I plotted the hyperparameters against each other to visualize the interdependence between hyperparameters. From the coarse hyperparameter search, I noticed the following trends: \begin{itemize} \item Mutation probability has a higher $\overline{k_{eff}}$, between 0.2 and 0.4. \item Mating probability has a higher $\overline{k_{eff}}$, between 0.1 and 0.3. \item Population size has a higher $\overline{k_{eff}}$, between 20 and 60. \item No obvious interdependence between hyperparameters. \end{itemize} Next, I proceeded to the fine searches. From Figure \ref{fig:hyperparameter_sens}, I narrowed down population size, mutation probability, and mating probability bounds, as shown in Table \ref{tab:hyperparameter_search}'s \textit{Fine Search 1 Bounds} column. I found no significant trends in the other hyperparameters, so I left them as is. I ran ten more experiments (25 to 34), sampling hyperparameters from the \textit{Fine Search 1 Bounds}. From these results, I conducted a second fine search with five experiments (35 to 39) with further tuned hyperparameter bounds, as shown in Table \ref{tab:hyperparameter_search}'s \textit{Fine Search 2 Bounds} column. I determined these new hyperparameter bounds based on these reasons: \begin{itemize} \item Mutation probability has a higher $\overline{k_{eff}}$, between 0.2 and 0.3. \item I overlooked $\overline{k_{eff}}$ peaking at mating probability between 0.45 and 0.6 in the previous \textit{Fine Search 1}, thus shifted the bounds. \item The highest $\overline{k_{eff}}$ occurred for \texttt{selTournament}. \item I narrowed down mating operator options to \texttt{cxBlend} and \texttt{cxOnePoint} since they had higher $\overline{k_{eff}}$. \item I selected arbitrary numbers for population size, selection individuals, and tournament size since they did not correlate with $\overline{k_{eff}}$ values. \end{itemize} Figure \ref{fig:input_hyperparameters_sens} shows the relationship between hyperparameter values and $a$, $b$, $c$ control parameters, final generation $k_{eff max}$, and final generation $\overline{k_{eff}}$. The coarse experiments' scatter points are $50\%$ transparent, while the fine experiments' scatter points are opaque. \begin{figure}[] \centering \makebox[\textwidth][c]{\includegraphics[width=1.3\linewidth]{input_hyperparameters_sens.png}} \caption{Hyperparameters search's results for all 40 experiments (coarse and fine). I plotted the hyperparameters against: a,b,c control parameters, each experiment's final generation $k_{eff max}$, and final generation $\overline{k_{eff}}$ with a third color dimension representing each experiment's final population's $\overline{k_{eff}}$ (color bar representing the $k_{eff}$ values provided on the right side of the figure). Coarse experiments' (0 to 24) scatter points are $50\%$ transparent, while the fine experiments' (24 to 39) scatter points are opaque. } \label{fig:input_hyperparameters_sens} \end{figure} In Figure \ref{fig:input_hyperparameters_sens}, on average, the fine experiments (opaque scatter points) have higher $\overline{k_{eff}}$, which indicates that the hyperparameter search process met its objective of finding hyperparameter bounds that enable quicker and more accurate optimization. Table \ref{tab:topfive} shows the hyperparameters for the five experiments with the highest final generation $\overline{k_{eff}}$. \begin{table}[] \centering \onehalfspacing \caption{Control Parameters, $k_{eff}$ results, and hyperparameter values for the five hyperparameter search experiments with the highest final generation $\overline{k_{eff}}$.} \label{tab:topfive} \footnotesize \makebox[\textwidth][c]{\begin{tabular}{p{3cm}p{3cm}p{3cm}p{3cm}p{3cm}p{3cm}} \hline & \multicolumn{5}{c}{\textbf{Experiment No.}} \\ \cline{2-6} \textbf{Control/Output Parameters} & \textbf{6} & \textbf{15} & \textbf{24} & \textbf{36} & \textbf{39}\\ \hline $\overline{k_{eff}}$ [-] & 1.39876 &1.40155&1.40118&1.39906&1.40165\\ $k_{eff max}$ [-] & 1.40954 &1.40440&1.40365&1.40590&1.40519\\ a [-] & 1.993&1.998&1.999&1.997&1.989\\ b [$\frac{radians}{cm}$] & 0.057&0.367&0.320&0.339&0.354\\ c [radians] & 3.571&3.022&3.615&3.053&3.143\\ \hline \textbf{Hyperparameter}& &&&&\\ Population size & 83 & 28&74&60&60\\ Generations &8&22&9&10&10 \\ Mutation probability & 0.32 &0.26&0.21&0.23&0.23\\ Mating probability & 0.17 &0.53&0.48&0.59&0.46\\ Selection operator & \texttt{selTournament} &\texttt{selTournament}&\texttt{selBest}&\texttt{selTournament}&\texttt{selTournament}\\ Selection individuals & 38 &14&25&15&15\\ Selection tournament size & 7 &5&-&5&5\\ Mutation operator & \texttt{mutPolynomial} \texttt{Bounded}&\texttt{mutPolynomial} \texttt{Bounded}&\texttt{mutPolynomial} \texttt{Bounded}&\texttt{mutPolynomial} \texttt{Bounded}&\texttt{mutPolynomial} \texttt{Bounded}\\ Mating operator & \texttt{cxOnePoint} &\texttt{cxOnePoint}&\texttt{cxUniform}&\texttt{cxBlend}&\texttt{cxBlend}\\ \hline \end{tabular}} \end{table} Figure \ref{fig:topfiveplot} shows the packing fraction distributions that produced the $k_{eff max}$ from the top five experiments. \begin{figure}[] \centering \makebox[\textwidth][c]{\includegraphics[width=1\linewidth]{topfive_plot.png}} \caption{Packing fraction distribution across the x-axis of the \acrfull{AHTR} slab for the five hyperparameter search experiments with the highest final generation $\overline{k_{eff}}$. $k_{eff}$ uncertainty are $\sim$130pcm.} \label{fig:topfiveplot} \end{figure} Four experiments had similar packing fraction distributions peaking at approximately 0.23 in the slab's center. In contrast, one experiment had an exponential-like distribution with a peak packing fraction of 0.31 at the slab's side. The similar final packing fraction distributions demonstrate genetic algorithms' robustness to find the optimal global solutions with different hyperparameters. I ran these simulations on the BlueWaters supercomputer \cite{ncsa_about_2017}. In each \gls{ROLLO} simulation, each generation runs a population size number of individual OpenMC simulations. Each OpenMC simulation takes approximately 13 minutes to run on a single BlueWaters XE node. With approximately 600 OpenMC evaluations per \gls{ROLLO} simulation, the \gls{ROLLO} simulation takes about 130 BlueWaters node-hours. The hyperparameter search ran 40 \gls{ROLLO} simulations, thus using approximately 5200 node-hours. \subsection{Results for Best Hyperparameter Set} \label{sec:best} I define the best-performing hyperparameter set as the experiment that produces the highest $\overline{k_{eff}}$ in its final generation. \textit{Fine Search 2}'s experiment 39 produces the best performing hyperparameter set, shown in Table \ref{tab:topfive}, with center-peaking packing fraction distribution of $max(k_{eff}) = 1.40519$. Experiment 39's $k_{eff max}$ exceeds the original straightened \gls{AHTR} configuration's $k_{eff}$ by $\sim2000$pcm, demonstrating that optimizing inhomogenous fuel distributions enables better neutronics. Figure \ref{fig:triso_distribution_sine_39} shows the packing fraction distribution that produced $k_{eff max} = 1.40519 \pm 0.00130$. \begin{figure}[] \centering \makebox[\textwidth][c]{\includegraphics[width=1.1\linewidth]{triso_distribution_sine_39.png}} \caption{Experiment 39 packing distribution that produced $k_{eff max} = 1.40519 \pm 0.00130$. Below: $PF(x) = (1.98\ sin(0.35x+3.14)+2) \times NF$ sine distribution with red points indicating the packing fraction at each cell. Above: Straightened \acrfull{AHTR} fuel slab with varying \gls{TRISO} particle distribution across ten cells based on the sine distribution. } \label{fig:triso_distribution_sine_39} \end{figure} Figures \ref{fig:keff_conv_39} and \ref{fig:pf_39} show the $k_{eff}$ evolution and packing fraction distribution through the best performing 39$^{th}$ experiment's generations. \begin{figure}[] \centering \begin{subfigure}{\textwidth} \makebox[\textwidth][c]{\includegraphics[width=1.1\linewidth]{keff_conv_39.png}} \caption{Minimum, average, and maximum $k_{eff}$ value evolution.} \label{fig:keff_conv_39} \end{subfigure} \begin{subfigure}{\textwidth} \makebox[\textwidth][c]{\includegraphics[width=1.1\linewidth]{pf_39.png}} \caption{$k_{eff max}$ packing fraction distribution evolution.} \label{fig:pf_39} \end{subfigure} \caption{Each generation's results for \gls{ROLLO}'s genetic algorithm optimization of the Straightened \acrfull{AHTR} Fuel Slab. The \gls{ROLLO} simulation used the 39$^{th}$ experiment's hyperparameter set. $k_{eff}$ uncertainty are $\sim$130pcm.} \label{fig:39} \end{figure} The $k_{eff max}$ converged quickly by generation 1; however, this usually does not occur. The genetic algorithm optimizes stochastically, resulting in the possibility that the algorithm randomly samples a control parameter set that maximizes the objective function early in the optimization process. The $\overline{k_{eff}}$ demonstrates how each generation's average $k_{eff}$ converges towards a higher value with each generation's improvements. To demonstrate how the genetic algorithm optimization process usually goes, Figures \ref{fig:keff_conv_15} and \ref{fig:pf_15} show the $k_{eff}$ evolution and packing fraction distribution through the second-best performing 15$^{th}$ experiment's generations. Experiment 15 demonstrates how both maximum and average $k_{eff}$ converge towards a higher $k_{eff}$ with improvements from each generation. \begin{figure}[] \centering \begin{subfigure}{\textwidth} \makebox[\textwidth][c]{\includegraphics[width=1.1\linewidth]{keff_conv_15.png}} \caption{Minimum, average, and maximum $k_{eff}$ values evolution.} \label{fig:keff_conv_15} \end{subfigure} \begin{subfigure}{\textwidth} \makebox[\textwidth][c]{\includegraphics[width=1.1\linewidth]{pf_15.png}} \caption{$k_{eff max}$'s packing fraction distribution evolution.} \label{fig:pf_15} \end{subfigure} \caption{ Results for each generation for \gls{ROLLO}'s genetic algorithm optimization of the Straightened \acrfull{AHTR} Fuel Slab. The \gls{ROLLO} simulation used the 15$^{th}$ experiment's hyperparameter set. $k_{eff}$ uncertainty are $\sim$130pcm.} \label{fig:15} \end{figure} In both Experiments 39 and 15, packing fractions peaked at approximately 0.23 in the slab center and decreased to zero at the sides. The amplitude, $a$, for the packing fraction distribution that produced $k_{eff max}$ for Experiment 39 and the other top-five experiments (Table \ref{tab:topfive}) have settled at the upper bound of approximately 2. A large sine distribution amplitude, $a$, demonstrates that a slab geometry with larger packing fraction variations results in a higher $k_{eff}$. These observations about packing fraction distribution for $k_{eff max}$ are consistent with conclusions from the \gls{FHR} benchmark (Chapter \ref{chap:fhr-benchmark}): a high $k_{eff}$ occurs with a good balance between fuel loading and moderation space. Fission occurs at high \gls{TRISO} particle concentration areas at thermal flux; however, the neutrons are born at fast flux and require moderation to slow down to thermal ranges. Therefore, larger moderation areas ensure higher resonance escape probability for the fast neutrons resulting in higher thermal flux, leading to more fission occurring and a higher $k_{eff}$. I also observed that \gls{TRISO} particle packing fraction peaks in the center of the slab, showing that if the optimization problem focuses purely on the slab's neutronics by maximizing $k_{eff}$, the fuel tends to culminate in the middle. Center-peaking fuel density is nonideal for other key reactor core qualities, such as maximal heat transfer and minimal power peaking factor (PPF). Thus, the \gls{AHTR} slab optimization problem must be extended to include these key reactor core qualities. \section{AHTR Multiphysics Model Preliminary Work} \label{sec:multiphysics_homo} % compare TRISO particles In the proposed PhD scope, I will use the open-source simulation tool, Moltres, to conduct \gls{AHTR} multiphysics simulations. Moltres, an application built atop the \gls{MOOSE} parallel finite element framework \cite{gaston_moose:_2009}, contains physics kernels and boundary conditions to solve arbitrary-group deterministic neutron diffusion and thermal-hydraulics \glspl{PDE} simultaneously on a single mesh \cite{lindsay_introduction_2018,park_advancement_2020}. \gls{AHTR} Moltres simulations will capture thermal feedback effects, absent from the purely neutronics OpenMC simulations. The objective of setting up the Moltres \gls{AHTR} simulation is to eventually couple Moltres with \gls{ROLLO} for \gls{AHTR} multiphysics optimization. The benefits of Moltres over other multiphysics software, RELAP5 and NESTLE (used previously for \gls{AHTR} modeling and described in Section \ref{sec:previous_ahtr}) for the purposes of this work, for coupled neutronics and thermal-hydraulics simulation are: \begin{itemize} \item Moltres supports up to 3-D meshes, solving neutron diffusion and thermal-hydraulics \glspl{PDE} simultaneously on the same mesh \cite{park_advancement_2020}. This is much more flexible than \gls{NESTLE} and RELAP5, which only support rectangular and hexagonal assembly lattices. Therefore, Moltres can explore arbitrary reactor geometries easily. \item Moltres tightly couples neutronics and thermal-hydraulics, thus providing higher accuracy in some tightly coupled problems. \item Moltres, a \gls{MOOSE}-based application, uses MPI for parallel computing, and compiles and runs on \glspl{HPC}. \end{itemize} To run Moltres simulations, the user provides group constant data from a neutron transport solver, such as OpenMC, for the Moltres multigroup neutron diffusion calculations and a mesh file representing the reactor geometry. A TRISO-level fidelity mesh file is impractical and will result in an extremely long Moltres runtime. For successful \gls{AHTR} Moltres simulation, I must establish suitable spatial and energy homogenization that preserves accuracy while maintaining an acceptable runtime. \subsection{Straightened AHTR Fuel Slab Multigroup Simulation} I use the continuous energy OpenMC simulation to generate multigroup cross section data defined over discretized energy groups and spatial segments. I then use OpenMC's multigroup calculation mode with the previously generated multigroup cross section data to calculate $k_{eff}$. Comparison of $k_{eff}$ for the continuous and multigroup simulations determines if the energy and spatial homogenization used are acceptable. In this section, the straightened AHTR fuel slab simulations use the \gls{TRISO} particle distribution that generated $k_{eff max}$ from the best hyperparameter set (Section \ref{sec:best}). For spatial homogenization of the straightened \gls{AHTR} fuel slab, I used OpenMC's \textit{cell} domain type to compute multigroup cross sections for different \textit{cells}. I discretized the slab into 13 \textit{cells}: FLiBe, left graphite, right graphite, and ten fuel cells (each cell has a different packing fraction). Figure \ref{fig:straightened_slab_mg} illustrates the \gls{AHTR} spatial homogenization for the OpenMC multigroup calculation. \begin{figure}[] \centering \includegraphics[width=\linewidth]{straightened_slab_mg.png} \raggedright \resizebox{0.5\textwidth}{!}{ \hspace{1cm} \fbox{\begin{tabular}{llll} \textcolor{fhrblue}{$\blacksquare$} & FLiBe & \textcolor{fhrgrey}{$\blacksquare$} & Left Graphite \\ \textcolor{fhrred}{$\blacksquare$} & Right Graphite & \textcolor{fhrpink}{$\blacksquare$} & Fuel cell 1/6 \\ \textcolor{fhryellow}{$\blacksquare$} & Fuel cell 2/7 & \textcolor{fhrorange}{$\blacksquare$} & Fuel cell 3/8 \\ \textcolor{fhrgreen}{$\blacksquare$} & Fuel cell 4/9 & \textcolor{fhrpurple}{$\blacksquare$} & Fuel cell 5/10 \\ \end{tabular}}} \caption{Straightened \acrfull{AHTR} fuel slab spatially discretized into 13 \textit{cells} for OpenMC multigroup calculation.} \label{fig:straightened_slab_mg} \end{figure} I used the four group energy structure derived by Gentry et al. \cite{gentry_development_2016} for \gls{AHTR} geometries. Table \ref{tab:energy_structures} defines the group boundaries. \begin{table}[] \centering \onehalfspacing \caption{4-group energy structures for \acrfull{AHTR} geometry derived by \cite{gentry_development_2016}.} \label{tab:energy_structures} \footnotesize \begin{tabular}{lll} \hline \multicolumn{3}{c}{\textbf{Group Boundaries [MeV]}} \\ \hline \textbf{Group $\#$}& \textbf{Upper Bound} & \textbf{Lower Bound} \\ \hline 1 & $2.0000\times 10^1$ & $9.1188\times 10^{-3}$ \\ 2 & $9.1188\times 10^{-3}$ & $2.9023\times 10^{-5}$\\ 3 & $2.9023\times 10^{-5}$ & $1.8554\times 10^{-6}$\\ 4 & $1.8554\times 10^{-6}$ & $1.0000\times 10^{-12}$\\ \hline \end{tabular} \end{table} Table \ref{tab:keff_multigroup} shows the $k_{eff}$ values from the continuous energy simulation and the spatial and energy homogenized simulation. The 26pcm difference between $k_{eff}$ values is within both uncertainty values, assuring that the spatial and energy homogenization used is suitable for generating group constants for Moltres. \begin{table}[] \centering \onehalfspacing \caption{Straightened \acrfull{AHTR} fuel slab's $k_{eff}$ for case with continuous energy and space and case with spatial and energy homogenization. Both simulations were run on one BlueWaters XE Node, with 80 active cycles, 20 inactive cycles, and 8000 particles.} \label{tab:keff_multigroup} \footnotesize \begin{tabular}{lll} \hline \textbf{Homogenization}& \textbf{$k_{eff}$} & \textbf{Simulation time [s]} \\ \hline None & $1.40473 \pm 0.00115$ & 808\\ Spatial and Energy & $1.40499 \pm 0.00109$ & 50\\ \hline \end{tabular} \end{table} \section{Summary} This chapter demonstrated the preliminary work completed for \gls{AHTR} optimization. I conducted a multigroup \gls{AHTR} slab simulation with four-group energy and spatial homogenization, which resulted in $k_{eff}$ within the uncertainty of the continuous energy simulation. The minimal $k_{eff}$ difference assures that I can use these homogenizations when generating group constants for Moltres. I also successfully applied \gls{ROLLO} to maximize $k_{eff}$ in a straightened \acrfull{AHTR} fuel slab by varying the \gls{TRISO} particle packing fraction distribution. The optimization process began with a coarse-to-fine random sampling hyperparameter search to find the genetic algorithm hyperparameters that worked best. Experiment 39 performed the best with a hyperparameter set that produced the highest final generation $\overline{k_{eff}}$ of 1.40165 $\pm$ 0.00130. The \gls{TRISO} particle packing fraction distribution that produced the final generation's maximum $k_{eff}$ of 1.40519 peaks at the slab's center with packing fraction distribution: $PF(x)=1.989\ sin(0.54x+3.143)$. This demonstration problem had a single objective function of maximizing $k_{eff}$. However, many other objectives should be considered, such as maximizing heat transfer and minimizing power peaking factor. Thus, in the next chapter, I propose future simulations for optimizing these objective functions simultaneously.
\section{Automated Variance Reduction Methods for Local Solutions} \label{sec:localVR} The next several sections (\ref{sec:localVR} through \ref{sec:AngleVR}) describe different ways that deterministically-obtained importance functions can be applied to variance reduction methods in practice. Local variance reduction methods are those that optimize a tally response in a localized region of the problem phase-space. These types of problems may be the most immediately physically intuitive to a user, where a person standing $x$ meters away from a source may wish to know their personal dose rate. In this section, notable automated deterministically-driven variance reduction methods that have been designed for such localized response optimization are described. Recall that Booth's importance generator (Section \ref{subsec:AutomatedMCVR}) was also designed for localized tally results, but will not be elaborated upon here. \subsection{CADIS} \label{sec:CADIS} In 1997, Haghighat and Wagner introduced the Consistent Adjoint-Driven Importance Sampling method (CADIS) \cite{wagner_automatic_1997,wagner_automated_1998,haghighat_monte_2003} as a tool for automatic variance reduction for local tallies in Monte Carlo. CADIS was unique in that it used the adjoint solution from a deterministic simulation to consistently bias the particle distribution and particle weights. Earlier methods had not ensured the consistency between source biasing and particle birth weights. CADIS was applied to a large number of application problems and performed well in reducing the variance for local tallies \cite{wagner_review_2011}. The next several paragraphs present and discuss the theory supporting CADIS. Note that the theory presented is specific to space-energy CADIS, which is what is currently implemented in existing software. The original CADIS equations are based on space and energy ($\vec{r}, E$) dependence, but not angle, so $\phi^{\dagger}$ can be used rather than $\psi^{\dagger}$. This does not mean that CADIS is not applicable to angle. This is merely a choice made by the software and method developers given the computational resources required to calculate and store full angular flux datasets, and the inefficiency that using angular fluxes might pose for problems where angle dependence is not paramount. In trying to reduce the variance for a local tally, we aim to encourage particle movement towards the tally or detector location. In other words, we seek to encourage particles to induce a detector response while discouraging them from moving through unimportant regions in the problem. Recall from Eqs. \eqref{eq:response1} and \eqref{eq:response2} that the total system response can be expressed as either an integral of $\psi^{\dagger}\: q_{e}$ (the adjoint flux and the forward source), or $\psi\: q_{e}^{\dagger}$ (the forward flux and the adjoint source). Also recall that the adjoint solution is a measure for response importance. \begin{subequations} \label{CADISmethod} To generate the biased source distribution for the Monte Carlo calculation, $\hat{q}$, should be related to its contribution to inducing a response in the tally or detector. It follows, then, that the biased source distribution is the ratio of the contribution of a cell to a tally response to the tally response induced from the entire problem. Thus, the biased source distribution for CADIS is a function of the adjoint scalar flux and the forward source distribtion $q$ in region $\vec{r}, E$, and the total response $R$ \begin{equation} \begin{split} \hat{q} & = \frac{\phi^{\dagger}(\vec {r} ,E)q(\vec {r} ,E)}{\iint\phi^{\dagger}(\vec {r} ,E)q(\vec {r} ,E) dE d\vec{r}} \\ & = \frac{\phi^{\dagger}(\vec {r} ,E)q(\vec {r} ,E)}{R}. \end{split} \label{eq:weightedsource} \end{equation} The starting weights of the particles sampled from the biased source distribution ($\hat{q}$) must be adjusted to account for the biased source distribution. As a result, the starting weights are a function of the biased source distribution and the original forward source distribution: \begin{equation} \begin{split} w_0 & = \frac{q}{\hat{q}} \\ & = \frac{R}{\phi^{\dagger}(\vec {r} ,E)}. \end{split} \label{eq:startingweight} \end{equation} Note that when Eq. \eqref{eq:weightedsource} is placed into Eq. \eqref{eq:startingweight}, the starting weight is a function of the total problem response and the adjoint scalar flux in $\vec{r}, E$. The target weights for the biased particles are given by \begin{equation} \hat{w} = \frac{R}{\phi^{\dagger}(\vec {r} ,E)}, \label{eq:WW} \end{equation} \end{subequations} where the target weight $\hat{w}$ is also a function of the total response and the adjoint scalar flux in region $\vec{r}, E$. The equations for $\hat{w}$ and $w_0$ match; particles are born at the same weight of the region they are born into. Consequently, the problem limits excessive splitting and roulette at the particle births, in addition to consistently biasing the particle source distribution and weights. This is the ``consistent'' feature of the CADIS method. CADIS supports adjoint theory by showing that using the adjoint solution ($\phi^{\dagger}$) for variance reduction parameter generation successfully improves Monte Carlo calculation runtime. CADIS showed improvements in the FOM when compared to analog Monte Carlo on the order of $10^2$ to $10^3$, and on the order of five when compared to ``expert'' determined or automatically-generated weight windows \cite{wagner_automated_1998, wagner_automated_2002} for simple shielding problems. For more complex shielding problems, improvements in the FOM were on the order of $10^1$ \cite{wagner_automatic_1997, wagner_automated_1998}. Note that CADIS improvement is dependent on the nature of the problem and that these are merely illustrative examples. \subsection{Becker's Local Weight Windows} \label{sec:beckerlocal} Becker's work in the mid- 2000s also explored generating biasing parameters for local source-detector problems \cite{becker_hybrid_2009}. Becker noted that in traditional weight window generating methods, some estimation of the adjoint flux is used to bias a forward Monte Carlo calculation. The product of this weight window biasing and the forward Monte Carlo transport ultimately distributed particles in the problem similarly to the contributon flux. In his work, Becker used a formulation of the contributon flux, as described in Eq. \eqref{eq.Cont-Flux} to optimize the flux at the forward detector location. The relevant equations are given by Eqs. \eqref{eq:beckerconributon} - \eqref{eq:beckeralpha}. \begin{subequations} \label{eq.beckerlocal} First, the scalar contributon flux $\phi^c$, which is a function of space and energy is calculated with a product of the deterministically-calculated forward and adjoint fluxes, where \begin{equation} \phi^c(\vec{r},E) = \phi(\vec{r},E) \phi^{\dagger}(\vec{r},E). \label{eq:beckerconributon} \end{equation} This is then integrated over all energy to obtain a spatially-dependent contributon flux \begin{equation} \tilde{\phi^c}(\vec{r}) = C_{norm}\int_0^{\infty } \phi^c(\vec{r},E) dE, \label{eq:beckerconributonspace} \end{equation} where the normalization constant, $C_{norm}$, for a given detector volume, $V_D$, is: \begin{equation} C_{norm} = \frac{V_D}{\int_{V_D}\int_0^{\infty } \phi^c(\vec{r},E) dE dV}. \end{equation} The space- and energy-dependent weight windows are given by: \begin{equation} \bar{w}(\vec{r},E) = \frac{B(\vec{r})}{\phi^{\dagger}(\vec{r},E)}\:, \label{eq:beckerlocalww} \end{equation} where \begin{equation} B(\vec{r}) = \alpha(\vec{r}) \tilde{\phi^c}(\vec{r}) + 1 - \alpha(\vec{r})\:, \end{equation} and \newcommand{\firs}{\cfrac{\tilde{\phi}^c_{max}}{\tilde{\phi}^c(\vec{r})}} \newcommand{\seco}{\cfrac{\tilde{\phi}^c(\vec{r})}{\tilde{\phi}^c_{max}}} \begin{equation} \alpha (\vec{r}) = \bigg[ 1 + \exp \bigg( \firs - \seco \bigg) \bigg]^{-1} . \label{eq:beckeralpha} \end{equation} \end{subequations} Becker found that this methodology compared similarly to CADIS for local solution variance reduction for a large challenge problem comprised of nested cubes. The particle density throughout the problem was similar between CADIS and Becker's local weight window. The FOMs were also relatively similar, but were reported only with Monte Carlo calculation runtimes (meaning that the deterministic runtimes were excluded). Note that Becker's method requires both a forward and an adjoint calculation to calculate the contributon fluxes, while CADIS requires only an adjoint calculation.
%!TEX root = ../../dissertation.tex \section{A recursive two-country economy} \label{sec:model} We study an exchange version of the \citet{Backus1994-bi} two-country business cycle model. Like their model, ours has two agents (one for each country), two intermediate goods (``apples'' and ``bananas''), and two final goods (one for each country). Unlike theirs, ours has (i)~exogenous output of intermediate goods, (ii)~a unit root in productivity, (iii)~recursive preferences, and (iv)~stochastic volatility in productivity growth in one country. The first is for convenience. The second allows us to produce realistic asset prices. We focus on the last two, specifically their role in the fluctuations in consumption and exchange rates. {\textit Preferences.\/} We use the recursive preferences developed by \citet{Epstein1989-mt,Kreps1978-gf}, and \citet{Weil1989-vy}. Utility from date $t$ on in country $j$ is denoted $U_{jt}$. We define utility recursively with the time aggregator $V$: \begin{eqnarray} U_{jt} &=& V [c_{jt}, \mu_{t} (U_{jt+1})] \;\;=\;\; [(1-\beta) c_{jt}^{\rho} + \beta \mu_{t} (U_{jt+1})^{\rho}]^{1/\rho} , \label{eq:time-agg} \end{eqnarray} where $c_{jt}$ is consumption in country $j$ and $\mu_t$ is a certainty equivalent function. The parameters are $ 0 < \beta < 1$ and $\rho \leq 1$. We use the power utility certainty equivalent function, \begin{eqnarray} \mu_{t} (U_{jt+1} ) &=& \big[ E_t (U_{jt+1}^{\alpha} ) \big]^{1/\alpha} , % \;\;=\;\; \Big[ \sum_{s_{t+1}} \pi(s_{t+1} | s^t) U_{j} (s^{t+1})^{\alpha} ) \Big]^{1/\alpha} \label{eq:cert-equiv} \end{eqnarray} where $E_t$ is the expectation conditional on the state at date $t$ and $\alpha \leq 1$. Preferences reduce to the traditional additive case when $\alpha = \rho$. Both $V$ and $\mu$ are homogeneous of degree one (hd1). The two functions together have the property that if consumption is constant at $c$ from date $t$ on, then $U_{jt} = c$. In standard terminology, $ 1/(1-\rho)$ is the intertemporal elasticity of substitution (IES) (between current consumption and the certainty equivalent of future utility) and $1-\alpha$ is risk aversion (RA) (over future utility). The terminology is somewhat misleading, because changes in $\rho$ affect future utility, the thing over which we are risk averse. As in other multi-good settings, there's no clean separation between risk aversion and substitutability. {\textit Technology.\/} Each country specializes in the production of its own intermediate good, ``apples'' in country 1 and ``bananas'' in country 2. In the exchange case we study, production in country $j$ equals its exogenous productivity: \begin{eqnarray} y_{jt} &=& z_{jt} . \label{eq:production} \end{eqnarray} Intermediate goods can be used in either country. The resource constraints are \begin{eqnarray} a_{1t} + a_{2t} &=& y_{1t} \label{eq:resource-a} \\ b_{1t} + b_{2t} &=& y_{2t} , \label{eq:resource-b} \end{eqnarray} where $b_{1t}$ is the quantity of country 2's good imported by country 1 and $a_{2t}$ is the quantity of country 1's good imported by country 2. Agents consume final goods, composites of the intermediate goods defined by the Armington aggregator $h$: \begin{eqnarray} c_{1t} &=& h (a_{1t}, b_{1t} ) \;\;=\;\; \big[(1-\omega) a_{1t}^{\sigma} + \omega b_{1t}^{\sigma}\big]^{1/\sigma} \label{eq:armington-1} \\ c_{2t} &=& h (b_{2t} , a_{2t}) \label{eq:armington-2} \end{eqnarray} with $ 0 \leq \omega \leq 1$ and $\sigma \leq 1$. The elasticity of substitution between the two intermediate goods is $1/(1-\sigma)$. The function $h$ is also hd1. We will typically use $\omega < 1/2 $, which puts more weight on the home good in the production of final goods. This ``home bias'' in final goods production is essential. If $\omega = 1/2$, the two final goods are the same. In this case, we have identical hd1 utility functions, and any optimal allocation involves a constant Pareto weight and proportional consumption paths. {\textit Shocks.\/} Fluctuations in this economy reflect variation in the productivities cum endowments $z_{jt}$ and the conditional variance of the first one. Logs of productivities have unit roots and are cointegrated: \begin{eqnarray} \left[ \begin{array}{c} \log z_{1t+1} \\ \log z_{2t+1} \end{array} \right] &=& \left[ \begin{array}{c} \log g \\ \log g \end{array} \right] + \left[ \begin{array}{cc} 1-\gamma & \gamma \\ \gamma & 1-\gamma \end{array} \right] \left[ \begin{array}{c} \log z_{1t} \\ \log z_{2t} \end{array} \right] + \left[ \begin{array}{c} v_t^{1/2} w_{1t+1} \\ v^{1/2} w_{2t+1} \end{array} \right] , \label{eq:lom-z} \end{eqnarray} with $0 < \gamma < 1/2$. The only asymmetry in the model is the conditional variance of productivity. The conditional variance $v$ of $\log z_{2t+1}$ is constant. The conditional variance $v_t$ of $\log z_{1t+1}$ is AR(1): \begin{eqnarray} v_{t+1} &=& (1-\varphi_v) v + \varphi_v v_t + \tau w_{3t+1} . \label{eq:lom-v} \end{eqnarray} The innovations $\{ w_{1t}, w_{2t}, w_{3t} \} $ are standard normals and are independent of each other and over time.
%!TEX root = /Users/stevenmartell/Documents/CURRENT PROJECTS/iSCAM-trunk/fba/BC-herring-2011/PRESENTATION/BC-Herring-2011.tex \section{Part II} % (fold) \label{sec:part_ii} \subsection{Introduction} % (fold) \label{sub:introduction} % \begin{frame}[t]\frametitle{Introduction} Objectives: \begin{enumerate} \item Data used in the 2011 assessment. \item Overview of the analytical methods. \item Present the 2011 stock assessment. \item Describe \& present the catch forecasts for 2012. \end{enumerate} \end{frame} %% subsection introduction (end) \subsection{2011 Data} % (fold) \label{sub:2011_data} % \begin{frame}[c]\frametitle{Data used in the 2011 stock assessment} \begin{itemize} \item Catch by gear type. \item Spawn survey data. \item Age-composition data. \item Empirical weight-at-age data. \end{itemize} \end{frame} % \begin{frame}[t]\frametitle{Catch by gear (1950:2011)} \only<1>{ \begin{figure}[htbp] \centering \includegraphics[clip,trim=0 304 300 0 ] {../FIGS/iscam_fig_CatchMajorAreas} \caption{Catch by gear for Haida Gwaii.} \end{figure} } \only<2>{ \begin{figure}[htbp] \centering \includegraphics[clip,trim=0 156 300 155 ] {../FIGS/iscam_fig_CatchMajorAreas} \caption{Catch by gear for Prince Rupert District.} \end{figure} } \only<3>{ \begin{figure}[htbp] \centering \includegraphics[clip,trim=0 0 300 301 ] {../FIGS/iscam_fig_CatchMajorAreas} \caption{Catch by gear for Central Coast.} \end{figure} } \only<4>{ \begin{figure}[htbp] \centering \includegraphics[clip,trim=300 304 0 0 ] {../FIGS/iscam_fig_CatchMajorAreas} \caption{Catch by gear for Strait of Georgia.} \end{figure} } \only<5>{ \begin{figure}[htbp] \centering \includegraphics[clip,trim=300 156 0 155 ] {../FIGS/iscam_fig_CatchMajorAreas} \caption{Catch by gear for West Coast of Vancouver Island.} \end{figure} } \end{frame} % \begin{frame}[t]\frametitle{Spawning activity in 2010} \only<1>{ \begin{figure}[htbp] \centering \includegraphics[scale=0.23] {../FIGS/PBSfigs/2011_spawn_HG_2E_July13} \includegraphics[scale=0.23] {../FIGS/PBSfigs/2011_spawn_HG_2W_July13} %{../FIGS/PBSfigs/2011-HG-Prelim-WG} \caption{2010 Spawning activity in Haida Gwaii.} \end{figure} } \only<2>{ \begin{figure}[htbp] \centering \includegraphics[scale=0.23] {../FIGS/PBSfigs/2011_spawn_PRD_July13} \caption{2010 Spawning activity in Prince Rupert District.} \end{figure} } \only<3>{ \begin{figure}[htbp] \centering \includegraphics[scale=0.23] {../FIGS/PBSfigs/2011_spawn_CCJuly13} \caption{2010 Spawning activity in Central Coast.} \end{figure} } \only<4>{ \begin{figure}[htbp] \centering \includegraphics[scale=0.23] {../FIGS/PBSfigs/2011_spawn_SOG_July13} \caption{2010 Spawning activity in Strait of Georgia.} \end{figure} } \only<5>{ \begin{figure}[htbp] \centering \includegraphics[scale=0.23] {../FIGS/PBSfigs/2011_spawn_WCVI_August16} \caption{2010 Spawning activity in West Coast Vancouver Island.} \end{figure} } \end{frame} % \begin{frame}[t]\frametitle{Spawn survey time series} \only<1>{ \begin{figure}[htbp] \centering \includegraphics[clip,trim=0 304 275 0] {../FIGS/iscam_fig_SurveyMajorAreas} \caption{Spawn survey series in Haida Gwaii.} \end{figure} } % \only<2>{ \begin{figure}[htbp] \centering \includegraphics[clip,trim=0 156 275 155] {../FIGS/iscam_fig_SurveyMajorAreas} \caption{Spawn survey series in Prince Rupert District.} \end{figure} } % \only<3>{ \begin{figure}[htbp] \centering \includegraphics[clip,trim=0 0 275 301] {../FIGS/iscam_fig_SurveyMajorAreas} \caption{Spawn survey series in Central Coast.} \end{figure} } % \only<4>{ \begin{figure}[htbp] \centering \includegraphics[clip,trim=275 304 0 0] {../FIGS/iscam_fig_SurveyMajorAreas} \caption{Spawn survey series in Strait of Georgia.} \end{figure} } % \only<5>{ \begin{figure}[htbp] \centering \includegraphics[clip,trim=275 156 0 155] {../FIGS/iscam_fig_SurveyMajorAreas} \caption{Spawn survey series in West Coast of Vancouver Island.} \end{figure} } \end{frame} % \begin{frame}[t]\frametitle{Age-composition data} \only<1>{ \begin{figure}[htbp] \centering \vspace{-0.5cm} \includegraphics [height=0.85\textheight,width=\textwidth] {../FIGS/iscam_fig_AgeCompsHG} \vspace{-1cm} \caption{Haida Gwaii: winter seine, seine-roe, gillnet.} \end{figure} } % \only<2>{ \begin{figure}[htbp] \centering \vspace{-0.5cm} \includegraphics [height=0.85\textheight,width=\textwidth] {../FIGS/iscam_fig_AgeCompsPRD} \vspace{-1cm} \caption{Prince Rupert District: winter seine, seine-roe, gillnet.} \end{figure} } % \only<3>{ \begin{figure}[htbp] \centering \vspace{-0.5cm} \includegraphics [height=0.85\textheight,width=\textwidth] {../FIGS/iscam_fig_AgeCompsCC} \vspace{-1cm} \caption{Central Coast: winter seine, seine-roe, gillnet.} \end{figure} } % \only<4>{ \begin{figure}[htbp] \centering \vspace{-0.5cm} \includegraphics [height=0.85\textheight,width=\textwidth] {../FIGS/iscam_fig_AgeCompsSOG} \vspace{-1cm} \caption{Strait of Georgia: winter seine, seine-roe, gillnet.} \end{figure} } % \only<5>{ \begin{figure}[htbp] \centering \vspace{-0.5cm} \includegraphics [height=0.85\textheight,width=\textwidth] {../FIGS/iscam_fig_AgeCompsWCVI} \vspace{-1cm} \caption{West Coast Vancouver Island: winter seine, seine-roe, gillnet.} \end{figure} } \end{frame} % \begin{frame}[t]\frametitle{Weight-at-age} \only<1>{ \begin{figure}[htbp] \centering \includegraphics[scale=0.4] {../FIGS/iscam_fig_weight-at-age_HG} \caption{Haida Gwaii: empirical weight-at-age (kg).} \end{figure} } % \only<2>{ \begin{figure}[htbp] \centering \includegraphics[scale=0.4] {../FIGS/iscam_fig_weight-at-age_PRD} \caption{Prince Rupert District: empirical weight-at-age (kg).} \end{figure} } % \only<3>{ \begin{figure}[htbp] \centering \includegraphics[scale=0.4] {../FIGS/iscam_fig_weight-at-age_CC} \caption{Central Coast: empirical weight-at-age (kg).} \end{figure} } % \only<4>{ \begin{figure}[htbp] \centering \includegraphics[scale=0.4] {../FIGS/iscam_fig_weight-at-age_SOG} \caption{Strait of Georgia: empirical weight-at-age (kg).} \end{figure} } % \only<5>{ \begin{figure}[htbp] \centering \includegraphics[scale=0.4] {../FIGS/iscam_fig_weight-at-age_WCVI} \caption{West Coast Vancouver Island: empirical weight-at-age (kg).} \end{figure} } % \end{frame} % % subsection 2011_data (end) \subsection{Analytical Methods} % (fold) \label{sub:analytical_methods} \begin{frame}[t]\frametitle{Analytics \& assumptions} \begin{itemize} \item<+-> All major and minor areas were assessed using \iscam. \item<+-> Reported catch: CV = 0.005 \item<+-> Spawn survey: proportional \& 100\% of $Z_t$. \item<+-> Dive survey more precise than surface survey. \item<+-> Fecundity $\propto$ mature weight-at-age. \item<+-> Seine gears: selectivity is asymptotic and time-invariant. \item<+-|alert@+> Gillnet gear: logistic selectivity with weigth-at-age covariates. \item<+-|alert@+> $P(\ln(q_1),\ln(q_2)) \sim $ Normal($\mu=-0.569,\sigma=0.274$). \item<+-> Homogenous errors in age-composition (multivariate logistic). \item<+-> Age-samples $<$0.02 pooled in adjacent cohort. \end{itemize} \end{frame} \begin{frame}[c]\frametitle{Diagnostics, Forecasts \& Catch Advice} \begin{description} \item<+->[Diagnostics] Retrospective analysis (sequential removal of the last 10 years of data). \item<+->[Forecasts] One-year projection of 3+ biomass with poor, average, good age-3 recruitment. \item<+->[Catch advice] Based on HCR with 20\% harvest rate if above cutoff. \end{description} \end{frame} % subsection analytical_methods (end) \subsection{Maximum Likelihood Estimates} % (fold) \label{sub:maximum_likelihood_estimates} % \begin{frame}[t]\frametitle{MLE: Spawn survey} \only<1>{ \begin{figure}[htbp] \centering \vspace{-1cm} \includegraphics[scale=0.4] {../FIGS/qPriorFigs/iscam_fig_survey_fit_HG} \vspace{-1cm} \caption{Haida Gwaii} \end{figure} } % \only<2>{ \begin{figure}[htbp] \centering \vspace{-1cm} \includegraphics[scale=0.4] {../FIGS/qPriorFigs/iscam_fig_survey_fit_PRD} \vspace{-1cm} \caption{Prince Rupert District} \end{figure} } % \only<3>{ \begin{figure}[htbp] \centering \vspace{-1cm} \includegraphics[scale=0.4] {../FIGS/qPriorFigs/iscam_fig_survey_fit_CC} \vspace{-1cm} \caption{Central Coast} \end{figure} } % \only<4>{ \begin{figure}[htbp] \centering \vspace{-1cm} \includegraphics[scale=0.4] {../FIGS/qPriorFigs/iscam_fig_survey_fit_SOG} \vspace{-1cm} \caption{Strait of Georgia} \end{figure} } % \only<5>{ \begin{figure}[htbp] \centering \vspace{-1cm} \includegraphics[scale=0.4] {../FIGS/qPriorFigs/iscam_fig_survey_fit_WCVI} \vspace{-1cm} \caption{West Coast Vancouver Island} \end{figure} } % \end{frame} % \begin{frame}[t]\frametitle{MLE: Residuals in age composition data} \only<1>{ \begin{figure}[htbp] \centering \vspace{-.75cm} \includegraphics[scale=0.5] {../FIGS/qPriorFigs/iscam_fig_agecompsresid_HG} \vspace{-1cm} \caption{Haida Gwaii} \end{figure} } % \only<2>{ \begin{figure}[htbp] \centering \vspace{-.75cm} \includegraphics[scale=0.5] {../FIGS/qPriorFigs/iscam_fig_agecompsresid_PRD} \vspace{-1cm} \caption{Prince Rupert District} \end{figure} } % \only<3>{ \begin{figure}[htbp] \centering \vspace{-.75cm} \includegraphics[scale=0.5] {../FIGS/qPriorFigs/iscam_fig_agecompsresid_CC} \vspace{-1cm} \caption{Central Coast} \end{figure} } % \only<4>{ \begin{figure}[htbp] \centering \vspace{-.75cm} \includegraphics[scale=0.5] {../FIGS/qPriorFigs/iscam_fig_agecompsresid_SOG} \vspace{-1cm} \caption{Strait of Georgia} \end{figure} } % \only<5>{ \begin{figure}[htbp] \centering \vspace{-.75cm} \includegraphics[scale=0.5] {../FIGS/qPriorFigs/iscam_fig_agecompsresid_WCVI} \vspace{-1cm} \caption{West Coast Vancouver Island} \end{figure} } % \end{frame} % \begin{frame}[t]\frametitle{MLE: Mortality} \only<1>{ \begin{figure}[htbp] \centering \vspace{-1cm} \includegraphics[scale=0.4] {../FIGS/qPriorFigs/iscam_fig_mortality_HG} \vspace{-1cm} \caption{Haida Gwaii} \end{figure} } % \only<2>{ \begin{figure}[htbp] \centering \vspace{-1cm} \includegraphics[scale=0.4] {../FIGS/qPriorFigs/iscam_fig_mortality_PRD} \vspace{-1cm} \caption{Prince Rupert District} \end{figure} } % \only<3>{ \begin{figure}[htbp] \centering \vspace{-1cm} \includegraphics[scale=0.4] {../FIGS/qPriorFigs/iscam_fig_mortality_CC} \vspace{-1cm} \caption{Central Coast} \end{figure} } % \only<4>{ \begin{figure}[htbp] \centering \vspace{-1cm} \includegraphics[scale=0.4] {../FIGS/qPriorFigs/iscam_fig_mortality_SOG} \vspace{-1cm} \caption{Strait of Georgia} \end{figure} } % \only<5>{ \begin{figure}[htbp] \centering \vspace{-1cm} \includegraphics[scale=0.4] {../FIGS/qPriorFigs/iscam_fig_mortality_WCVI} \vspace{-1cm} \caption{West Coast Vancouver Island} \end{figure} } % \end{frame} % \begin{frame}[t]\frametitle{Age-2 recruits} \begin{figure}[htbp] \centering \vspace{-1cm} \includegraphics[scale=0.5]{../FIGS/qPriorFigs/iscam_fig_recruitment} \vspace{-1cm} \caption{Age-2 recruits with 0.33 and 0.66 quantiles.} \end{figure} \end{frame} %% subsection maximum_likelihood_estimates (end) \subsection{Diagnostics} % (fold) \label{sub:diagnostics} % \begin{frame}[t]\frametitle{Diagnostics: Retrospective plots} \begin{figure}[htbp] \centering \vspace{-.75cm} \includegraphics[scale=0.45]{../FIGS/qPriorFigs/iscam_fig_sbt_retrospective} \vspace{-1cm} \caption{Retrospective estimates of spawning biomass.} \end{figure} \end{frame} % \begin{frame}[t]\frametitle{Diagnostics: Trace plots} \begin{figure}[htbp] \centering \vspace{-0.75cm} \includegraphics[scale=0.35]{../FIGS/qPriorFigs/iscam_fig_trace_SOG} \vspace{-0.65cm} \caption{Posterior samples: 1 million, thin 500, Strait of Georgia} \end{figure} \end{frame} % \begin{frame}[t]\frametitle{Diagnostics: Pair plots} \begin{figure}[htbp] \centering \vspace{-1cm} \includegraphics[scale=0.4] {../FIGS/qPriorFigs/iscam_fig_pairs_SOG} \vspace{-0.85cm} \caption{Posterior samples from leading parameters \& derived variables.} \end{figure} \end{frame} % \begin{frame}[t]\frametitle{Diagnositcs: Marginal posteriors} \begin{figure}[htbp] \centering \includegraphics[scale=0.4]{../FIGS/qPriorFigs/iscam_fig_marginals_SOG} \caption{Strait of Georgia: Marginal \& prior distributions.} \end{figure} \end{frame} %% subsection diagnostics (end) \subsection{Advice for management} % (fold) \label{sub:advice_for_management} \begin{frame}[t]\frametitle{Uncertainty in 2011 spawning biomass} \only<1>{ \begin{figure}[htbp] \centering \includegraphics[scale=0.35] {../FIGS/qPriorFigs/iscam_fig_2011_SBt_posteriors} \caption{Marginal posterior distributions for 2011 spawning biomass.} \end{figure} } % \only<2>{ \begin{figure}[htbp] \centering \includegraphics[scale=0.35] {../FIGS/qPriorFigs/iscam_fig_2011_depletion_posteriors} \caption{Marginal posterior distributions for 2011 spawning biomass depletion.} \end{figure} } % \only<3>{ \begin{table} \caption{Estimates of 2011 spawning biomass, $B_0$, and depletion.} \begin{center} \begin{tiny} \begin{tabular}{l>{\bfseries}ccc|>{\bfseries}ccc|>{\bfseries}ccc} \hline &\multicolumn{3}{c}{$SB_{2011}$} &\multicolumn{3}{c}{$B_0$} &\multicolumn{3}{c}{$SB_{2011}/B_0$}\\ Stock &Median & 2.5\% & 97.5\% &Median & 2.5\% & 97.5\% &Median & 2.5\% & 97.5\% \\ \hline HG & 16.58 & 7.70 &33.63& 41.74 &30.05 &61.51& 0.39 &0.19 &0.75 \\ PRD & 27.05 & 14.45& 50.59 & 78.56 & 54.15 &150.18 & 0.34 & 0.15 & 0.68\\ CC & 14.67 & 7.28 &27.28 &62.40& 48.47& 85.06 & 0.23 & 0.12 & 0.41\\ SOG & 125.14 & 70.43& 217.95 &140.05& 110.47& 184.24 & 0.89 & 0.53 & 1.45\\ WCVI & 14.68 & 6.99 &27.63& 59.58& 46.84& 78.53& 0.24 & 0.12& 0.43\\ \hline \end{tabular} \end{tiny} \end{center} \end{table} } \end{frame} % \begin{frame}[t,shrink=35]\frametitle{Forecast: Old cutoffs} \input{../TABLES/qPriorTables/DecisionTableOldCuttoffs} \end{frame} % \begin{frame}[t,shrink=35]\frametitle{Forecast: New cutoffs} \input{../TABLES/qPriorTables/DecisionTableNewCuttoffs} \end{frame} % subsection advice_for_management (end) \subsection{Outstanding issues} % (fold) \label{sub:outstanding_issues} \begin{frame}[t]\frametitle{Outstanding issues} \begin{itemize} \item<+-> Reference points (e.g., B$_0$) based on non-stationary parameters (e.g., $M_t$, selectivity, growth). \item<+-> Strong retrospective bias in PRD. \item<+-> Formal evaluation of alternative hypotheses. \end{itemize} \end{frame} % subsection outstanding_issues (end) \subsection{Response to reviewers} % (fold) \label{sub:response_to_reviewers} \begin{frame}[t]\frametitle{Risk based decision making} \begin{block}{Considerations} \begin{itemize} \item What is the probability of the stock falling below the cutoff for a given catch option? \item What is the probability of the spawning stock declining? \item What is the probability of the harvest rate exceeding 0.2? \end{itemize} \end{block} \end{frame} % \begin{frame}[t]\frametitle{Probability of something bad happening} \only<1>{ \begin{figure}[htbp] \centering \includegraphics[height=0.8\textheight] {../FIGS/qPriorFigs/iscam_fig_risk_HG} \vspace{-0.5cm} \caption{Haida Gwaii} \end{figure} } % \only<2>{ \begin{figure}[htbp] \centering \includegraphics[height=0.8\textheight] {../FIGS/qPriorFigs/iscam_fig_risk_PRD} \vspace{-0.5cm} \caption{Prince Rupert District} \end{figure} } % \only<3>{ \begin{figure}[htbp] \centering \includegraphics[height=0.8\textheight] {../FIGS/qPriorFigs/iscam_fig_risk_CC} \vspace{-0.5cm} \caption{Central Coast} \end{figure} } % \only<4>{ \begin{figure}[htbp] \centering \includegraphics[height=0.8\textheight] {../FIGS/qPriorFigs/iscam_fig_risk_SOG} \vspace{-0.5cm} \caption{Strait of Georgia} \end{figure} } % \only<5>{ \begin{figure}[htbp] \centering \includegraphics[height=0.8\textheight] {../FIGS/qPriorFigs/iscam_fig_risk_WCVI} \vspace{-0.5cm} \caption{West Coast Vancouver Island} \end{figure} } \end{frame} % subsection response_to_reviewers (end) % section part_ii (end)
\documentclass[11pt]{article} \usepackage{setspace} \usepackage{pxfonts} \usepackage{graphicx} \usepackage{geometry} \geometry{letterpaper,left=.5in,right=.5in,top=0in,bottom=.75in,headsep=5pt,footskip=20pt} \title{Problem Set 4 -- Hodgkin-Huxley neuron model} \author{Computational Neuroscience Summer Program} \date{June, 2011} \begin{document} \maketitle In this problem set you will be building a Hodgkin-Huxley model neuron. Write up your results in a text editor of your choosing. Include any relevant figures. Include a printout of your Matlab code as well as any calculations that aren't in the code. You may work individually or in groups, but each student should hand in their own report. \subsection*{Equations} \begin{center} \begin{tabular}{l|l|l} $\tau_x(V)\frac{dx}{dt} = x_\infty(V) - x$ & $\tau_x(V) = \frac{1}{\alpha_x(V) + \beta_x(V)}$ & $x_\infty(V) = \frac{\alpha_x(V)}{\alpha_x(V) + \beta_x(V)}$ \\ \hline $\alpha_n(V) = \frac{0.01(V+55)}{1 - exp(-.1(V+55))}$ & $\alpha_m(V) = \frac{0.1(V+40)}{1 - exp(-.1(V+40))}$ & $\alpha_h(V) = 0.07*exp(-.05(V+65))$\\ \hline $\beta_n(V) = 0.125*exp(-0.0125(V+65))$ & $\beta_m(V) = 4*exp(-.0556(V+65))$ & $\beta_h(V) = \frac{1}{1 + exp(-.1(V+35))}$\\ \hline $P_K = n^4$ & $P_{Na} = m^3h$ &\\ \hline $g_K = \bar{g}_KP_K$ & $g_{Na} = \bar{g}_{Na}P_{Na}$ &\\ \end{tabular} \end{center} \subsection*{Problems} \paragraph{1.} Build a Hodgkin-Huxley model using the following equation, in addition to those listed above: \[ V(t+dt) = V(t) +\frac{\left[-i_m + \frac{I_{ext}}{A}\right]dt}{c_m}, \] where \[ i_m = \bar{g}_L(V(t) - E_L) + g_K(V(t) - E_K) + g_{Na}(V(t) - E_{Na}), \] and where $\bar{g}_L = 0.003$ mS/mm$^2$, $\bar{g}_K = 0.36$ mS/mm$^2$, $\bar{g}_{Na} = 1.2$ mS/mm$^2$, $E_L = -54.387$ mV, $E_K = -77$ mV, $E_{Na} = 50$ mV, and $c_m = 0.1$ nF/mm$^2$. Set $V(0) = E = -65$ mV. You should simulate a 15 ms segment (use $dt \leq 0.01$ ms). Pulse the neuron with a 5 nA/mm$^2$ pulse between 5 and 8 ms in your simulation; this should result in a single action potential at between 5 and 10 ms. Plot the $V$, $n$, $m$, and $h$ as a function of time. Congratulations --- you've just replicated a Nobel prize-worthy result! \paragraph{2.} Explain what's happening in problem 1. In particular: what do $V$, $n$, $m$, and $h$ mean in terms of the simulated neuron? Explain the relative time course of each of these variables. How do $n$, $m$, and $h$ interact to produce $V$? \paragraph{3.} Tetrodotoxin (TTX), a pufferfish-derived toxin, selectively blocks voltage-sensitive sodium channels, effectively setting $P_{Na} = 0$. Simulate the addition of TTX at $t = 0$ ms, and re-plot $V$, $n$, $m$, and $h$. Does the neuron still fire an action potential? Why or why not? \paragraph{4.} Tetraethylammonium (TEA) selectively blocks voltage-sensitive potassum channels, effectively setting $P_{K} = 0$. Simulate the addition of TEA at $t = 0$ ms, and re-plot $V$, $n$, $m$, and $h$. Does the neuron still fire an action potential? Why or why not? (Remember to remove TTX first!) \paragraph{5. Challenge problem.} How might you compute the firing rate of your Hodgkin-Huxley neuron? Simulate a 1000 ms run with a pulse from 250 to 750 ms, and measure how many spikes are fired. Repeat this procedure for 10 pulse strengths between 0.01 and 10 nA. Plot firing rate as a function of pulse strength. \end{document}
\documentstyle[fullpage]{article} \input{tex_stuff.tex} \begin{document} \bibliographystyle{alpha} \title{{\bf The Omega Calculator and Library}, {\em version 1.1.0}} \author{ Wayne Kelly, Vadim Maslov, William Pugh, \\ Evan Rosser, Tatiana Shpeisman, Dave Wonnacott } \maketitle \section{Introduction} This document gives an overview of the Omega library and describes the Omega Calculator, a text-based interface to the Omega library. A separate document describes the C++ interface to the Omega library and we are still working on a third document that describes some of the algorithms used in implementing the Omega library. The Omega library manipulates integer tuple relations and sets, such as $$\{[i,j] \rightarrow [j,j'] : 1 \leq i < j < j' \leq n\} {\rm\ and\ } \{ [ i ,j ] : 1 \leq i < j \leq n\}$$ Tuple relations and sets are described using Presburger formulas\cite{presburger1,Shostak77,presburger2,presburger2a} a class of logical formulas which can be built from affine constraints over integer variables, the logical connectives $\neg$, $\land$ and $\lor$, and the quantifiers $\forall$ and $\exists$. The best known upper bound on the performance of an algorithm for verifying Presburger formulas is $2^{2^{2^{n}}}$ \cite{presburger3}, and we have no reason to believe that our method provides better worst-case performance. However, we have found it to be reasonably efficient for our applications. The following relation, which maps 2-tuples to 1-tuples: $\{[i, j] \rightarrow [i] : 1 \le i,j \le 2\}$ represents the following set of mappings: $\{[1,1]\rightarrow[1],\ [1,2]\rightarrow[1],\ [2,1]\rightarrow[2],\ [2,2]\rightarrow[2]\}$. In addition to variables in the input and output tuples, the Presburger formulas may also contain free variables. This allows parameterized relations to be described. For example, $n$ and $m$ are free in $\{ [i, j] \rightarrow [i] : 1 \le i \le n \land 1 \le j \le m \}$. The language allows new relations to be defined in terms of existing relations by providing a number of relational operators. The relational operations provided include intersection, union, composition, inverse, domain, range and complement. For example, $\{[p] \rightarrow [2p, q]\}$ {\tt compose} $\{[i,j]\rightarrow[i]\}$ evaluates to $\{[i,j]\rightarrow[2i,q]\}$. Relations are simplified before being displayed to the user. This involves transforming them into disjunctive normal form and removing redundant constraints and conjuncts. During simplification, it may be determined that the relation contains no points or contains all points, in which case the simplified constraints will be False or True respectively. For example, $\{[i]\rightarrow[i]\}$ {\tt intersect} $\{[i]\rightarrow[i+1]\}$ evaluates to $\{[i]\rightarrow[i'] : {\tt False}\}$. The copyright notice and legal fine print for the Omega calculator and library are contained in the README and omega.h files. Basically, you can do anything you want with them (other than sue us); if you redistribute it you must include a copy of our copyright notice and legal fine print. \section{Omega Calculator invocation, syntax and semantics} The calculator reads from the file given as the first argument, or standard input, and prints results on standard output. You can specify several command line flags. Using {\tt -D}{\em mk}, where $m$ is a character and $k$ is a digit, sets the debugging level to $k$ for module $m$. Using {\tt -G}$g$ sets the maximum number of inequalities in a conjunct to $g$. Using {\tt -E}$e$ sets the maximum number of equalities in a conjunct to $E$. In version 1.1.0, we intend to change our data structures so that these will not need to be specified. There is also a limit on the maximum number of variables in a conjunct, but this cannot be changed at run-time. It is given by {\tt maxVars} in {\tt oc.h}. We also intend to make this go away. The input is a series of statements terminated by semicolons. A \# indicates that the rest of the line is a comment. The syntax {\tt <<}{\em filename}{\tt >>} can occur anywhere (and indicates that the text of the file is to be included here. The statements can have one of the forms listed in Figure~\ref{IPIstatements}. {\em RelExpr} is a short form of {\em Relational Expression}. \begin{figure}[tbh] \begin{tabular}{l|p{4.5in}} Syntax & Semantics \\\hline {\tt symbolic} {\em varList} & Defines the variable names as symbolic constants that can be used in all later expressions. \\ {\em var} := {\em RelExpr} & Computes the relational expression and binds the variable name to the result. \\ {\em RelExpr} & Computes and prints the relational expression. \\ {\tt codegen} $\ldots$ & This is described in Section \ref{section:codegen}. \\ {\em RelExpr} {\tt subset} {\em RelExpr} & Prints True if the first relation is a subset of the second, otherwise prints False. \\ \end{tabular} \caption{Omega Calculator statements} \label{IPIstatements} \end{figure} Figures \ref{figure:example1} and \ref{figure:example2} show a sample session with the Omega Calculator. Lines starting with \# are input to the Omega calculator, the other lines are output from the calculator. \input{calculator-ex.tex} Some relational operations may not preserve the names of input and output variables. If this happens, the variables get default names: {\tt In\_}$n$ for input variables and {\tt Out\_}$n$ for output variables, where $n$ is a position of variables in its tuple. When printing, primes are added to variables to distinguish between multiple variables with the same name. In input, primes may also be used to distinguish between multiple variables with the same name: the primes are stripped before being passed to the Omega library. \section{Relations} \subsection{Building relations} A relation is an operand of a relational expression. Its syntax is: \begin{quote} {\tt \{ [} {\em InputList} {\tt ] -> [} {\em OutputList} {\tt ] :} {\em formula} {\tt \}} \end{quote} {\em InputList} and {\em OutputList} are lists of tuple elements. A tuple element can be: \begin{tabular}{cp{5in}} {\em var} & The corresponding tuple variable is given this name. If a variable with that name is already in scope, an equality is added forcing this tuple variable to be equal to the value of the previous definition. \\ {\em exp} & The tuple variable is unnamed and forced to be equal to the expression. \\ {\em exp}:{\em exp} & The tuple variable is unnamed and forced to be greater than or equal to the first expression and less than or equal to the second. \\ {\em exp}:{\em exp}:{\em int} & The tuple variable is unnamed and forced to be greater than or equal to the first expression and less than or equal to the second, and the difference between the tuple variable and the first expression must be an integer multiple of the integer. \\ {\tt *} &The tuple variable is unnamed. \end{tabular} The {\em formula} is optional. If it is omitted, no constraints other than those introduced by the input and output expressions are imposed upon the relation's variables. Otherwise, the formula describes additional constraints on variables used in the relation. \subsection{Sets} In addition to relations, the system can represent {\em sets}. When a relation is declared with only one tuple, as in: \begin{quote} {\tt \{ [} {\em SetList} {\tt ] :} {\em formula} {\tt \}} \end{quote} then the relation becomes a set. The variables that are used to describe a set ({\em SetList}) are called {\em set variables} rather than input or output variables. \subsection{Presburger formula operations} As mentioned above, the tuples belonging to the relation are defined by a {\em Presburger formula}. This formula is built from constraints using the operations described in Figure~\ref{FormulaOps}. \begin{figure}[tbh] \begin{tabular}{l|lll} Name & \multicolumn{3}{l}{Notation} \\\hline And & {\em formula} {\tt \&} {\em formula} & {\em formula} {\tt \&\&} {\em formula} & {\em formula} {\tt and} {\em formula} \\ Or & {\em formula} {\tt |} {\em formula} & {\em formula} {\tt ||} {\em formula} & {\em formula} {\tt or} {\em formula} \\ Not & {\tt !} {\em formula} & & {\tt not} {\em formula}\\ Exists & \multicolumn{3}{l}{{\tt exists} ($v_1,...,v_n$: {\em formula})} \\ Forall & \multicolumn{3}{l}{{\tt forall} ($v_1,...,v_n$: {\em formula})} \\ Parentheses & ({\em formula}) \\ Constraint & {\em constraint} \\ \end{tabular} \caption{Presburger formula syntax} \label{FormulaOps} \end{figure} \subsection{Constraints and arithmetic and comparison operations} A Presburger formula is built from constraints using the operations described in the previous subsection. In this subsection we describe the syntax of individual constraints. A constraint is a series of expression lists, connected with the arithmetic relational operators {\tt =, !=, >, >=, <, <=}. An example is {\tt 2i + 3j <= 5k,p <= 3x-z = t}. When an constraint contains a comma-separated list of expressions, it indicates that the same constraints should be introduced for each of the expressions. The constraint {\tt a,b <= c,d > e,f} translates to the constraints $$a \leq c \land a \leq d \land b \leq c \land b \leq d \land c > e \land c > f \land d > e \land d > f$$ Expressions can be of the forms (where {\em var} is a variable, {\em integer} is an integer constant, and $e$, $e_1$, and $e_2$ are expressions): {\em var}, {\em integer}, $e$, {\em integer} $e$, $e_1 + e_2$, $e_1 - e_2$, $e_1 \ast e_2$, $- e$, $(e)$. An important restriction is that all expressions in the constraints must be affine functions of the variables. For example, $2\ast x$ is legal, $x \ast 2$ is legal, but $x \ast x$ is illegal. \section{Relational and set operations} A relational expression is an expression over individual relations. The relational operations defined in the system are listed in Figures \ref{RelOps1} and \ref{RelOps2}. Here $r, r_1, r_2$ are relations and $s, s_1, s_2$ are sets. \begin{figure}[tbp] \begin{tabular}{l|l|p{3.5in}} Name & Syntax & Explanation \\\hline Union & $r = r_1$ {\tt union} $r_2$ & $x \rightarrow y \in r$ iff $x \rightarrow y \in r_1$ or $x \rightarrow y \in r_1$ \\ & $s = s_1$ {\tt union} $s_2$ & $x \in s$ iff $x \in s_1$ or $x \in s_1$ \\ Intersection & $r = r_1$ {\tt intersection} $r_2$ & $x \rightarrow y \in r$ iff $x \rightarrow y \in r_1$ and $x \rightarrow y \in r_1$ \\ & $s = s_1$ {\tt intersection} $s_2$ & $x \in s$ iff $x \in s_1$ and $x \in s_1$ \\ Difference & $r = r_1 - r_2$ & $x \rightarrow y \in r$ iff $x \rightarrow y \in r_1$ and $x \rightarrow y \not\in r_1$ \\ & $s = s_1 - s_2$ & $x \in s$ iff $x \in s_1$ and $x \not\in s_1$ \\ Complement & $r =$ {\tt complement} $r_1$ & $x \rightarrow y \in r$ iff $x \rightarrow y \not\in r_1$ \\ & $s =$ {\tt complement} $s_1$ & $x \in s$ iff $x \not\in r_1$ \\ Composition & $r = r_1$ {\tt compose} $r_2$ & $x \rightarrow y \in r$ iff $\exists y \st x \rightarrow y \in r_2$ and $ y \rightarrow z \in r_1$ \\ Application & $s = r_1 (s_2)$ & $x \in s$ iff $\exists y \st x \rightarrow y \in r_1$ and $ y \in s_2$ \\ & $r = r_1 (r_2)$ & Equivalent to $r_1$ {\tt compose} $r_2$ \\ Join & $ r = r_1 . r_2 $ & Equivalent to $r_2$ {\tt compose} $r_1$\\ & & $x \rightarrow y \in r$ iff $\exists y \st x \rightarrow y \in r_1$ and $ y \rightarrow z \in r_2$ \\ Inverse & $r =$ {\tt inverse} $r_1$ & $x \rightarrow y \in r $ iff $y \rightarrow x \in r_1$\\ Domain & $s =$ {\tt domain} $r_1$ & $x \in s$ iff $\exists y \st x \rightarrow y \in r_1$\\ Range & $s =$ {\tt range} $r_1$ & $y \in s$ iff $\exists x \st x \rightarrow y \in r_1$\\ Restrict Domain & $r = r_1 ~\verb+\+~ s_2$ & $x \rightarrow y \in r$ iff $x \rightarrow y \in r_1$ and $x \in s_2$ \\ Restrict Range & $r = r_1 ~/~ s_2$ & $x \rightarrow y \in r$ iff $x \rightarrow y \in r_1$ and $y \in s_2$ \\ Gist & $r=$ {\tt gist} $r_1$ {\tt given} $r_2$ & Computes gist of relation $r_1$ given relation $r_2$. \\ \end{tabular} \caption{Relational operations, part 1} \label{RelOps1} \end{figure} \begin{figure}[tbp] \begin{tabular}{l|l|p{3.5in}} Name & Syntax & Explanation \\\hline Hull & $r=$ {\tt hull} $r_1$ & Computes an single convex region that contains all of $r_1$. Not as tight as the convex hull, but intended to be fairly fast. \\ Convex Hull & $r=$ {\tt ConvexHull} $r_1$ & Computes the convex hull \cite{Schrijver86,Wilde93} of $r_1$. May be prohibitively expensive to compute and/or induce numeric overflow of coefficients (leading to a core dump) \\ Affine Hull & $r=$ {\tt AffineHull} $r_1$ & Computes the affine hull \cite{Schrijver86,Wilde93} of $r_1$. May be prohibitively expensive to compute and/or induce numeric overflow of coefficients (leading to a core dump) \\ Linear Hull & $r=$ {\tt LinearHull} $r_1$ & Computes the linear hull \cite{Schrijver86,Wilde93} of $r_1$. May be prohibitively expensive to compute and/or induce numeric overflow of coefficients (leading to a core dump) \\ Conic Hull & $r=$ {\tt ConicHull} $r_1$ & Computes the conic or cone hull \cite{Schrijver86,Wilde93} of $r_1$. May be prohibitively expensive to compute and/or induce numeric overflow of coefficients (leading to a core dump) \\ Farkas Lemma & $r=$ {\tt farkas} $r_1$ & Applies Farkas's lemma \cite{Schrijver86,Wilde93} to $r_1$. In the result, the values of the variables correspond to legal values for coefficients of equations implied by the convex hull of $r_1$. Also happens to represent the convex hull of $r_N$ using a points and rays representation. See \cite{Wilde93} for a more detailed explaination. \\ Convex Check & $r=$ {\tt ConvexCheck} $r_1$ & Returns the convex hull of $r_1$ if we can easily determine that it is equal to $r_1$, otherwise returns $r_1$. \\ Pairwise Convex Check & $r=$ {\tt PairwiseCheck} $r_1$ & Checks to see if any two conjuncts in $r_1$ can be replaced exactly by their convex hull (doing so if possible). \\ Transitive Closure & $r = r_1 {\tt +}$ & Least fixed point of $r^+ \equiv r \cup (r \circ r^+)$ \\ & $r = r_1 {\tt +}$ {\tt within} $b$ & Least fixed point of $r^+$ for dependence relation $r$ within iteration space $b$ \\ Conic Closure & $r = r_1 {\tt @}$ & Gives a simple dependence relation $r$ such that any linear schedule for all of the dependences in $r$ is non-negative if and only if it is legal for all of the dependences in $r_1$. Note that $r_1 {\tt +} \subseteq r_1 {\tt @}$. We previously refered to this as affine closure \cite{uniform2.4}. \\ Cross-product & $r = r_1$ {\tt *} $r_2$ & $x \rightarrow y \in r $ iff $x \in r_1$ and $y \in r_2$ \\ Create superset & $r= $ {\tt supersetof} $r_1$ & $r$ is inexact with lower bound $r_1$ \\ Create subset & $r= $ {\tt subsetof} $r_1$ & $r$ is inexact with upper bound $r_1$ \\ Create upper bound & $r= $ {\tt upper\_bound} $r_1$ & $r$ is an exact relation and is an upper bound on $r_1$ (all UNKNOWN constraints in $r_1$ are interpreted as TRUE) \\ Create lower bound & $r= $ {\tt lower\_bound} $r_1$ & $r$ is an exact relation and a lower bound on $r_1$ (all UNKNOWN constraints in $r_1$ are interpreted as FALSE) \\ Get an example & $r= $ {\tt example} $r_1$ & $r \subseteq r_1$ and all variables in $r$ are single-valued \\ Symbolic example & $r= $ {\tt sym\_example} $r_1$ & $r \subseteq r_1$ and all non-symbolic variables in $r$ are single-valued \end{tabular} \caption{Relational operations, part 2} \label{RelOps2} \end{figure} \section{Code Generation} \label{section:codegen} The Omega Calculator incorporates an algorithm for generating code for multiple, overlapping iteration spaces \cite{Uniform4}. Each iteration space has an associated statement or block of statements. The syntax is \centerline{{\tt codegen} [{\em effort}] $IS_1, IS_2, \ldots ,IS_n$ [ {\tt given} {\em known}] } Each iteration space $IS_i$ can be specified either as a set representing the iteration space, or as an original iteration space and a transformation, {\em T}:{\em IS}, where {\em IS} is the original iteration space and {\em T} is a relation defining an affine, 1-1 mapping to a new iteration space. That is, given a point in the original iteration space, the mapping specifies the point in the new iteration space at which to execute that iteration. The effort value specifies the amount of effort to be used to eliiminate sources of overhead in the generated code. Sources of overhead include if statements an {\tt min} and {\tt max} functions in loop bounds. If not specified, the effort level is 0. The different effort levels are: \begin{description} \item{-2} Minimal possible effort. Loop bounds may not be finite. \item{-1} Forces finite bounds \item{0} Forces finite bounds and tries to remove {\tt if}'s within most deeply nested loops (at a possible cost of code duplication). \item{1} removes {\tt if}'s within most deeply nested loops and loops one short of being most deeply nested. \item{2} $\ldots$ and loops two short of being most deeply nested. \item{$x$} $\ldots$ and loops $x$ short of being most deeply nested. \end{description} The known information, if specified, is used to simplify the generated code. The generated code will not be correct if known is not true. Currently, the known relation needs to be a set with the same arity and the transformed iteration space. A discussion of program transformations using this framework is given in \cite{Uniform2.1,Uniform2.3,Uniform3}. The following is an example of code generation, given three original iteration spaces and mappings. The transformed code requires the traditional transformations loop distribution and imperfectly nested triangular loop interchange. Below, the program information has been extracted and presented to the Omega Calculator in relation form. \vspace{0.2in} {\bf Original code} \begin{verbatim} do 30 i=2,n 10 sum(i) = 0. do 20 j=1,i-1 20 sum(i) = sum(i) + a(j,i)*b(j) 30 b(i) = b(i) - sum(i) \end{verbatim} {\bf Schedule} (for parallelism) $$T10:\{\ [\ i\ ] \rightarrow\ [\ 0,i,0,0\ ]\ \}$$ $$T20:\{\ [\ i,j\ ] \rightarrow\ [\ 1,j,0,i\ ]\ \}$$ $$T30:\{\ [\ i\ ] \rightarrow\ [\ 1,i-1,1,0\ ]\ \}$$ {\bf Omega Calculator output:} \input{calculator-ex2.tex} \section{Inexact Relations} The special constraint UNKNOWN represents one or more additional constraints that are not known to the Omega Library. Such constraints can arise from uses of uninterpreted function symbols or transitive closure (as described below), or when the user explicitly requests it. Such relations require conservative treatment from the library (e.g., subtracting a conjunct containing UNKNOWN from a relation must return that relation, since the unknown constraints might make the conjunct unsatisfiable.) The {\tt upper\_bound} and {\tt lower\_bound} operations can be used to produce exact relations from inexact relations. They are produced by treating UNKNOWN constraints as TRUE or FALSE, respectively. \section{Presburger Arithmetic with Uninterpreted Function Symbols} The Omega Calculator allows certain restricted uses of {\em uninterpreted function symbols} in a Presburger formula. Functions may be declared in the {\tt symbolic} statement as \begin{quote} {\tt symbolic} {\em Function} ({\em Arity}) \end{quote} where {\em Function} is the function name and {\em Arity} is its number of arguments. Functions of arity 0 are symbolic constants. Functions may only be applied to a prefix of the input or output tuple of a relation, or a prefix of the tuple of a set. The function application may list the names of the argument variables explicitly ({\em not yet supported}), or use the abbreviations {\em Function({\tt In})}, {\em Function({\tt Out})}, and {\em Function({\tt Set})}, to describe the application of a function to the appropriate length prefix of the desired tuple. Our system relies on the following observation: Consider a formula $F$ that contains references $f(i)$ and $f(j)$, where i and j are free in $F$. Let $F'$ be $F$ with $f_{i}$ and $f_{j}$ substituted for $f(i)$ and $f(j)$. $F$ if satisfiable iff $((i = j) \Rightarrow (f_{i} = f_{j})) \land F'$ is satisfiable. For more details, see \cite{Shostak79}. % Robert % Shostak's paper ``A Practical Decision Procedure for Arithmetic with % Function Symbols'' \cit(JACM, April 1979). Presburger Arithmetic with uninterpreted function symbols is in general undecidable, so in some circumstances we will have to produce approximate results (as we do with the transitive closure operation) \cite{transitiveClosure}. The following examples show some legal uses of uninterpreted function symbols in the Omega Calculator: \input{calculator-ex3.tex} \section{Reachability} Consider a graph where each directed edge is specified as a tuple relation. Given a tuple set for each node representing starting states at each node, the library can compute which nodes of the graph are reachable from those start states, and the values the tuples can take on. The syntax is: \begin{verbatim} reachable ( [list of nodes] ) { [node:startstates] | node_i->node_j:transition] } \end{verbatim} For example, \begin{verbatim} reachable (a,b,c) { a->b:{[1]->[2]}, b->c:{[2]->[3]}, a:{[1]}}; \end{verbatim} The transitions and start states may be any expression that evaluates to a relation. You can also compute a tuple set containing the reachable values a t given node; for example: \begin{verbatim} R := reachable of c in (a,b,c) { a->b:{[1]->[2]}, b->c:{[2]->[3]}, a:{[1]}}; \end{verbatim} The current implementation is very straightforward and can be very slow. \section{Current limitations} The transitive closure operation will not work on a relation with uninterpreted function symbols of arity $> 0$. Any operation that requires the projection of input or output variables (such as composition) may return inexact results if variables in the argument list of a function symbol are projected. \bibliography{para} \end{document}
\chapter{Applications Beyond Analysis and Resynthesis} \subsection{Discussion of the Stop Function}\label{section:audioEffects:stopFunction} In this section, the stop function of the detection stage is revisted. \subsubsection{Residual Power Threshold} Perhaps the most striaghtforward stop function is checking power of the residual signal, $x_r$. Given a threshold $t$: \begin{align}\label{eq:audioEffects:stopFunction:powerThreshold} s(y, t) = \begin{cases} 0, & \text{if } t \geq \sum_{N = 0}^{N-1} y[n]^2 \\ 1, & \text{otherwise} \end{cases} \end{align} When the periodicity transform is performed short-time on a signal, that is, in frames, it is typically best to set $t$ equal to some fractional amount of the input vector $x$ so as to allow the threshold for frame $i$, $t_i$, to be dynamic: \begin{align*} t_i = t \sum_{N = 0}^{N-1} x[n]^2 \end{align*} where $0 \leq t < 1$. There are of course many variations of the above thresholding formulation in Equation \eqref{eq:audioEffects:stopFunction:powerThreshold} such as $||x||_p$. If one uses the simple threshold stop function, it is important to recognize that it is possible to continue finding periodic data in a residual that carries no meaningful information as to the ``essence'' of the input signal (refer to the paragraph beginning this section). Although these ``phantom'' periodicities may help the convex program to better minimize the reconstruction error, they often add no value and can often distort the useful periodicities already detected. As an example, let $x$ be the combination of three sinusoids with periods 17, 21, and 50, plus zero-mean Gaussian noise with a SNR of -18 dB: \begin{figure}[h] \centering % \includegraphics[width=0.75\textwidth]{PATH/TO/MY/FIG} \caption{[A signal $x$ that is the sum of three equal-amplitude sinusoids with $p = \{17, 21, 50\}$ plus zero-mean Gaussain noise.]A signal $x$ that is the sum of three equal-amplitude sinusoids with $p = \{17, 21, 50\}$ plus zero-mean Gaussain noise.} \label{fig:audioEffects:stopFunction:residual:sinesPlusNoise} \end{figure} where $N$ is the length of the signal and is equal to 1000, and $G(n)$ is the Gaussian noise at sample $n$. What periods are found at various values of $t$? Below is the output of the convex program using the projection in Equation \eqref{eq:intro:sethares} and different values of $t$. We also set $t$ directly to simplify: \begin{figure}[h] \centering % \includegraphics[width=0.75\textwidth]{PATH/TO/MY/FIG} \caption[A figure showing the effect of different threshold values for the stop function.\index{Values of $t$}]{Results of period detection using various values of $t$. \emph{Top Panel:} $t = 0.2$. Note that not enough data is captured and only two periods are found. \emph{Middle Panel:} $t = 0.1$ Since $t$ is exactly equal to the SNR of the signal, we find that the three periods we expect are found before the algorithm terminates. \emph{Bottom Panel:} $t = 0.05$ Although we find the three periods we expect, the algorithm also finds periods in the residual noise. This has the further effect of distorting the already detected periodic waveforms as one will see in Section \ref{ch3:recoveringWaveforms}} \label{fig:audioEffects:stopFunction:thresholdEffect} \end{figure} Notice that in the bottom panel, $t$ is set too low and we therefore see many periods which, while they do ``exist'', do not necessarly add information but are rather imparted by the projection process and numerical happenstance. In a close-to-ideal world (one in which we admit noise), one would simply set $t$ to be the level of the noise floor in the signal. In this way, one would only capture the periodic components while leaving the noise (relatively) untouched. This, of course, is not possible in real data and is especially prone to error when non-integer periods are present. See Section \ref{ch3:nonintegerPeriods} for a longer discussion. \subsubsection{Sum of the Power of the Periodic Components} A novel way to approch the problem and one that keeps in mind the qualitative criteria of ``listenability'' is to check whether or not the sum of the powers of the detected periodic waveforms exceeds the power of the original signal. For convenience, we define the power to be $E(x) \equiv \sum_{n = 0}^{N - 1} |x[n]|^2$: \begin{align} s(x, X_Q) = \begin{cases} 0, & \text{if } E(x) \leq \sum_{x_q \in X_Q} E(x_q) \\ 1, & \text{otherwise} \end{cases} \end{align} where $X_Q$ is the set of projections of the best periods acquired through projection of $x_r$ onto $P_p$. Note that these projections are also of length $N$. This often results in a less-than-perfect reconstruction from a residual minimization standpoint but in practice has shown better listenability of the components themselves. \subsubsection{Decrease in the Total Power of Periodic Components} An interesting phenomenon was observed in processing real data, often data that contains noise and/or non-integer periodicities whereby the sums of the derived periodic components \emph{decreases} as more iterations are performed. \subsubsection{Lack of Significant Periods} If the input to the ML estimator is $x = \mathcal{N}(0, \sigma^2)$, the resulting powers of the periods, normalized as Equation \eqref{eq:intro:sethares:periodicNormGamma}, we see that there are no significant peaks in the periodogram: \begin{figure}[h] \centering % \includegraphics[width=0.75\textwidth]{PATH/TO/MY/FIG} \caption[Periodogram of zero-mean Gaussian noise for $2 \leq p \leq 500$ for $N = 1000$] {Periodogram of zero-mean Gaussian noise for $2 \leq p \leq 500$ for $N = 1000$. Notice the conspicuous lack of significant periods for the ML estimator to choose from.} \label{fig:audioEffects:gaussianPeriodogram} \end{figure} We can measure this by defining the ``flatness'' of the periodogram to be: \begin{align} \label{eq:audioEffects:flatness} P_{\text{flatness}}(P) &= \frac { % e^{\big( \frac{1}{N} \sum_{n=0}^{N-1} \ln P[n] \big)} \sqrt[N]{\Pi_{n=0}^{N-1} P_n} % \big( \Pi_{n=0}^{N-1} P_n \big)^{\frac{1}{N}} } { \frac{1}{N} \sum_{n=0}^{N-1} P_n } \end{align} where $N$ is the number of periods we search for (i.e. $N = P_{max} - P_{min}$) and $t$ is again a threshold, all typically converted to decibels. Notice that this is identical to the spectral flatness measure that is common in measuring the Fourier Transform of a discrete time signal. It proves useful in this regard as well, as a simple but effective measure of determining whether or not there remain any more significant periods in the data. Suppose $x = S_1 + \mathcal{N}(0, \sigma^2)$ and $||S_1||_2 \ll ||\mathcal{N}(0, \sigma^2)||_2$. The resulting periodogram will be very similar to that of pure zero-mean Gaussain noise yet we know there is a periodic signal in $x$. What ought to be the interpretation in this case? In practice, it was found that in this case, the periodic signal $S_1$ is so insignificant so as to have no meaningful value as to the constitution of $x$. In other words, in such a case nothing of value is lost by disregarding $S_1$ given its overall weakness in the signal. \subsection{Time Stretching} \subsection{Monaural Source Separation}
% !TeX spellcheck = en_GB \section{Extratropical Cyclones}\label{sec:ext_cyclone} %\cite{markowski_mesoscale_2011} %' midlatitude synoptic-scale motions are arguably solely driven by baroclinic instability; extratropical cyclones are the dominant weather system of midlatitudes on the synoptic scale. Baroclinic instability is most likely to be realized by disturbances.' %\\ %Extratropical highs and lows have a time-scale of several days and the horizontal extension of several kilometre. \\ %Extratropical cyclones develop with the formation of fronts. \\ %'The destabilization of layers via the potential instability %mechanism is probably important in the formation %of mesoscale rainbands within the broader precipitation %shields of extratropical cyclones on some occasions, especially %when potentially unstable layers are lifted over a front. %Potential instability also is often cited as being important %in the development of deep moist convection.' 'Despite the common presence of %potential instability, however, it usually does not play a role %in the destabilization of the atmosphere that precedes the %initiation of convection.' \\ %'Not only are synoptic fronts and their %associated baroclinity important for the development of %larger-scale extratropical cyclones, but in some situations %evenmesoscale boundaries can influence larger-scale extratropical %cyclones.' \\ %'In the Norwegian cyclone model, the cold front %moves faster than the warm front, eventually overtaking %it, resulting in occlusion of the extratropical cyclone, with %the occluded front being the surface boundary along which %the cold front has overtaken the warm front.'
\documentclass{article} \usepackage{graphicx} \usepackage{subcaption} \begin{document} \section{ AND Gate} The expression C = A X B reads as “C equals A AND B“ The multiplication sign (X) stands for the AND operation, same for ordinary multiplication of 1s and 0s. \begin{figure}[h!] \centering \begin{subfigure}[b]{0.4\linewidth} \includegraphics[width=\linewidth]{AND.png} \end{subfigure} \subsection{NB} The AND operation produces a true output (result of 1) only for the single case when all of the input variables are 1 and a false output (result of 0) where one or more inputs are 0. \begin{subfigure}[b]{0.4\linewidth} \includegraphics[width=\linewidth]{AND table.png} \end{subfigure} \end{figure} \end{document}
\clearpage \section{Appendix} This section gives quick instructions for installing some needed software packages to establish the end-to-end autotuning system. Please consult individual software releases for detailed installation guidance. \subsection{Patching Linux Kernels with perfctr} This is required before you can install PAPI on Linux/x86 and Linux/x86\_64 platforms. Take PAPI 3.6.2 as an example, the steps to patch your kernel are: \begin{itemize} \item Find the latest perfctr patch which matches your Linux distribution from \textit{papi-3.6.2/src/perfctr-2.6.x/patches}. For Red Hat Enterprise Linux 5 (or CentOS 5), the latest kernel patch is \textit{patch-kernel-2.6.18-92.el5-redhat}. \item Get the Linux kernel source rpm package which matches the perfctr kernel patch found in the previous step. You can find kernel source rpm packages from one of the many mirror sites. For example, \textit{wget http://altruistic.lbl.gov/mirrors/centos/5.2/updates/SRPMS/kernel-2.6.18-92.1.22.el5.src.rpm} \item Install the kernel source rpm package. With a root privilege, simply type: \begin{verbatim} rpm -ivh kernel*.src.rpm \end{verbatim} The command will generate a set of patch files under \textit{/usr/src/redhat/SOURCES}. \item Generate the kernel source tree from the patch files. This step may require the \textit{rpm-build} and \textit{redhat-rpm-config} packages to be installed first. \begin{verbatim} yum install rpm-build redhat-rpm-config # with the root privilege cd /usr/src/redhat/SPECS rpmbuild -bp --target=i686 kernel-2.6.spec # for x86 platforms rpmbuild -bp --target=x86_64 kernel-2.6.spec #for x86_64 platforms \end{verbatim} \item Copy the kernel source files and create a soft link. Type \begin{verbatim} cp -a /usr/src/redhat/BUILD/kernel-2.6.18/linux-2.6.18.i686 /usr/src ln -s /usr/src/linux-2.6.18.i686 /usr/src/linux \end{verbatim} \item Now you can patch the kernel source files to support perfctr. Type \begin{verbatim} cd /usr/src/linux /path/to/papi-3.6.2/src/perfctr-2.6.x/update-kernel \ --patch=2.6.18-92.el5-redhat \end{verbatim} \item Configure your kernel to support hardware counters. \begin{verbatim} cd /usr/src/linux make clean make mrproper yum install ncurses-devel make menuconfig \end{verbatim} Enable all items for \textit{performance-monitoring counters support} under the menu item of \textit{processor type and features}. \item Build and install your patched kernel. \begin{verbatim} make -j4 && make modules -j4 && make modules_install && make install \end{verbatim} \item Configure perfctr as a device that is automatically loaded each time you boot up your machine. \begin{verbatim} cd /home/liao6/download/papi-3.6.2/src/perfctr-2.6.x cp etc/perfctr.rules /etc/udev/rules.d/99-perfctr.rules cp etc/perfctr.rc /etc/rc.d/init.d/perfctr chmod 755 /etc/rc.d/init.d/perfctr /sbin/chkconfig --add perfctr \end{verbatim} \end{itemize} With the kernel patched, it is straightforward to install PAPI. \begin{verbatim} cd /home/liao6/download/papi-3.6.2/src ./configure make make test make install # with a root privilege \end{verbatim} %---------------------------------------------- \subsection{Installing BLCR} BLCR (the Berkeley Lab Checkpoint/Restart library)'s installation guide can be found at \url{http://upc-bugs.lbl.gov/blcr/doc/html/BLCR_Admin_Guide.html}. We complement the guide with some Linux-specific information here. It is recommended to use a separate build tree to compile the library. \begin{verbatim} mkdir buildblcr cd buildblcr # explicitly provide the Linux kernel source path ../blcr-0.8.2/configure --with-linux=/usr/src/linux-2.6.18.i686 make # using a root account make install make insmod check # Doublecheck kernel module installation # You should find two module files: blcr_imports.ko blcr.ko ls /usr/local/lib/blcr/2.6.18-prep/ \end{verbatim} To configure your system to load BLCR kernel modules at bootup: \begin{verbatim} # copy the sample service script to the right place cp blcr-0.8.2/etc/blcr.rc /etc/init.d/. # change the module path inside of it vi /etc/init.d/blcr.rc #module_dir=@MODULE_DIR@ module_dir=/usr/local/lib/blcr/2.6.18-prep/ #run the blcr service each time you boot up your machine chkconfig --level 2345 blcr.rc on # manually start the service # error messages like "FATAL: Module blcr not found." can be ignored. /etc/init.d/blcr.rc restart Unloading BLCR: FATAL: Module blcr not found. FATAL: Module blcr_imports not found. [ OK ] Loading BLCR: FATAL: Module blcr_imports not found. FATAL: Module blcr not found. [ OK ] \end{verbatim}
\section{Cut Property and Cycle Property} %%%%%%%%%%%%%%%%%%%% \begin{frame}{A generic MST algorithm} \end{frame} %%%%%%%%%%%%%%%%%%%% \begin{frame}{Cut property (strong)} \begin{exampleblock}{Cut property (strong)} \begin{itemize} \item Graph $G = (V, E)$ \item $X$ is some part of an MST $T$ of $G$ \item Any cut $(S, V \setminus S)$ \emph{s.t.} $X$ does not cross $(S, V \setminus S)$ ­\item Let $e$ be a lightest edge across $(S, V \setminus S)$ \end{itemize} Then $X \cup \set{e}$ is some part of an MST $T'$ of $G$. \end{exampleblock} \begin{proof} \centerline{Exchange argument} \end{proof} \end{frame} %%%%%%%%%%%%%%%%%%%% \begin{frame}{Cut property (strong)} Correctness of Prim's and Kruskal's algorithms. \end{frame} %%%%%%%%%%%%%%%%%%%% \begin{frame}{Cut property (weak)} \begin{exampleblock}{Cut Property \pno{3.6.18 (a)}} \begin{itemize} \item Graph $G = (V, E)$ \item Any cut $(S, V \setminus S)$ where $S, V-S \neq \emptyset$ \item Let $e = (u,v)$ be \emph{a} minimum-weight edge across $(S, V \setminus S)$ \end{itemize} Then $e$ must be in \emph{some} MST of $G$. \end{exampleblock} \begin{center} ``a'' $\to$ ``the'' $\implies$ ``some'' $\to$ ``any'' \end{center} \end{frame} %%%%%%%%%%%%%%%%%%%% \begin{frame}{Applications of cut property} \begin{exampleblock}{Application of cut property (Problem 6.10)} \begin{enumerate}[(1)] \setcounter{enumi}{2} \item $e \in G$ is a lightest edge $\implies$ $e \in \exists$ MST of $G$ \item $e \in G$ is the unique lightest edge $\implies$ $e \in \forall$ MST of $G$ \end{enumerate} \end{exampleblock} \end{frame} %%%%%%%%%%%%%%%%%%%% \begin{frame}{Applications of cut property} \begin{exampleblock}{Wrong divide\&conquer algorithm for MST (Problem 6.14)} \begin{itemize} \item $G = (V, E, w)$ \item $(V_{1}, V_{2}): ||V_{1}| - |V_{2}|| \le 1$ \item $T_{1} + T_{2} + \set{e}$: $e$ is a lightest edge across $(V_{1}, V_{2})$ \end{itemize} \end{exampleblock} \fignocaption{width = 0.30\textwidth}{figs/divide-conquer-mst-counterexample.pdf} \end{frame} %%%%%%%%%%%%%%%%%%%% \begin{frame}{Cycle property (weak)} \begin{exampleblock}{Cycle property (Problem 6.13--2)} \begin{itemize} \item $G = (V,E,w)$ \item Let $C$ be any cycle in $G$ \item $e = (u,v)$ is \emph{a} maximum-weight edge in $C$ \end{itemize} Then $\exists \textrm{ MST } T \text{ of } G: e \notin T$. \end{exampleblock} \begin{center} ``a'' $\to$ ``the'' $\implies$ ``some'' $\to$ ``any'' \end{center} \end{frame} %%%%%%%%%%%%%%%%%%%% \begin{frame}{Applications of cycle property} \begin{exampleblock}{Anti-Kruskal algorithm (Problem 6.13--3)} \centerline{\href{https://en.wikipedia.org/wiki/Reverse-delete_algorithm}{Reverse-delete algorithm (wiki)}} \[ O(m \log n (\log \log n)^3) \] \end{exampleblock} \begin{proof} \textbf{Invariant: } If $F$ is the set of edges remained at the end of the while loop, then there is some MST that are a subset of $F$. \end{proof} \begin{alertblock}{Reference} \begin{itemize} \item ``On the Shortest Spanning Subtree of a Graph and the Traveling Salesman Problem'' by Kruskal, 1956. \end{itemize} \end{alertblock} \end{frame} %%%%%%%%%%%%%%%%%%%% \begin{frame}{Application of cycle property} \begin{exampleblock}{(Problem 6.13--1)} \begin{enumerate}[(1)] \item $e \notin$ any cycle of $G$ $\implies$ $e \in \forall$ MST \end{enumerate} \end{exampleblock} \centerline{By contradiction.} \end{frame} %%%%%%%%%%%%%%%%%%%% \begin{frame}{Application of cycle property} \begin{exampleblock}{(Problem 6.10)} \begin{enumerate}[(1)] \item $|E| > |V| - 1$, $e$ is the unique max-weight edge of $G$ $\implies$ $e \notin \forall$ MST \item $\exists C \subseteq G$, $e$ is the unique max-weight edge of $C$ $\implies$ $e \notin \forall$ MST \setcounter{enumi}{4} \item Cycle $C \subseteq G$, $e \in C$ is the unique lightest edge of $G$ $\implies$ $e \in \forall$ MST \end{enumerate} \end{exampleblock} \end{frame} %%%%%%%%%%%%%%%%%%%% \begin{frame}{Unique MST} \begin{exampleblock}{Unique MST (Problem 6.12--1)} Distinct weights $\implies$ Unique MST. \end{exampleblock} \[ \Delta E = \set{e \mid e \in T_1 \setminus T_2 \lor e \in T_2 \setminus T_1} \] \end{frame} %%%%%%%%%%%%%%%%%%%% \begin{frame}{Unique MST} \begin{exampleblock}{Unique MST (Problem 6.12--2)} Unique MST $\centernot\implies$ Equal weights. \end{exampleblock} \fignocaption{width = 0.20\textwidth}{figs/unique-mst-unique-weight-counterexample.pdf} \end{frame} %%%%%%%%%%%%%%%%%%%% \begin{frame}{Unique MST} \begin{exampleblock}{Unique MST (Problem 6.12--3)} Unique MST $\centernot\implies$ Minimum-weight edge across any cut is unique. \end{exampleblock} \fignocaption{width = 0.20\textwidth}{figs/unique-mst-cut-counterexample.pdf} \begin{theorem} Minimum-weight edge across any cut is unique $\implies$ Unique MST. \end{theorem} \end{frame} %%%%%%%%%%%%%%%%%%%% \begin{frame}{Unique MST} \begin{exampleblock}{Unique MST (Problem 6.12--3)} Unique MST $\centernot\implies$ Maximum-weight edge in any cycle is unique. \end{exampleblock} \fignocaption{width = 0.20\textwidth}{figs/unique-mst-cycle-counterexample.pdf} \begin{theorem}[Conjecture] Maximum-weight edge in any cycle is unique $\implies$ Unique MST. \end{theorem} \fignocaption{width = 0.15\textwidth}{figs/unique-mst-cycle-noncounterexample.pdf} \end{frame} %%%%%%%%%%%%%%%%%%%% \begin{frame}{Unique MST} \begin{exampleblock}{Unique MST (Problem 6.12--4)} Decide whether a graph has a unique MST? \end{exampleblock} \vspace{0.60cm} \begin{enumerate} \item Exchange argument based on cut property and cycle property \item Ties breaking in Prim's and Kruskal's algorithms \end{enumerate} \end{frame} %%%%%%%%%%%%%%%%%%%%
% {{cookiecutter.author}} % {{cookiecutter.email}} % === CONCLUSION === \chapter{Conclusion} \label{conclusion} This chapter summarizes and concludes the contents of the paper.
%!TeX root = personal_device \documentclass[paper.tex]{subfiles} \begin{document} % %\begin{autem} %What follows is intended to be a casual, first-principles e. Be very careful with its conclusions. %\end{autem} % %{\color{red} speculation \{ } % %%\clearpage {\Large \it The plausibility of low-cost microwave masks}\\ With the most recent few generations of semiconductor processes, producing significant powers in the X-band has become inexpensive. Silicon transistors are limited in their output power and gain; Silicon-on-insulator topologies This is perhaps most readily illustrated with the commercial HB100 radar module. This device implements a complete Doppler radar with two RF FETs and one dielectric resonator on a standard FR4 substrate. It operates at 10.6 GHz, yet are produced for under \$3. Our crude experimentation has yielded about 10 mW with a single SiGe:C transistor, the Infineon BFP620 (\$ 0.34 apiece \@ 1000-of.). For the personal microwave sterilizer, given the threshold levels found by Yang, this corresponds to a cost per sterilized cubic centimeter of approx. \cite{BFP620H7764XTSA1}. Trivially extending great work by \cite{Focusing} on passive reflectarrays, a 40-element active-antenna phased array, each element of which consists of a negative-resistance device such as the BFP620 transistor, a tuning varactor, a patch antenna, and a resonator, each contributing a pulsed tone of 500 nanoseconds length and 10 milliwatts of RF power, and a focal point spatial scan rate and pulse repetition frequency of 6 KHz. produces a field pattern which, when scanned, appears to be suitable to deny respiratory transmission in a 'face shield' configuration. Such a field would comply with all standards by at least a factor of 20. %figure from ipynb \begin{figure}[H] \captionsetup{singlelinecheck = false, justification=justified} \centering \includegraphics[width=\textwidth]{muller_test_cropped.jpg} \caption{\\ How simple an active antenna element can be. This is based on the feedback-loop oscillator of \cite{SmallSize2008}, and uses a single CEL CE3520K3 GaAs FET (\$2.5) and one 100pF capacitor. It oscillated with extreme instability at about 5 GHz.} \end{figure} \begin{figure}[H] \captionsetup{singlelinecheck = false, justification=justified} \centering \includegraphics[width=\textwidth]{my_photo-17.jpg} \caption{\\ A wideband tunable 7 GHz VCO based on \cite{TripleTuned2008}. This uses an Infineon BFP620 SiGe:C transistor (\$0.3) and a network of four varactor diodes. Unfortunately, the Si varactors did not appear to have a sufficiently high Q to prevent mode-hopping, and the output spectrum reflects the ignorance of its designer; however, it appeared to be capable of producing the 10 dBm required above.} \end{figure} \begin{figure}[H] \captionsetup{singlelinecheck = false, justification=justified} \centering \includesvg[width=\textwidth]{personal_device_E} \caption{Near-field focused phased array} \end{figure} % a prototype oscillator Injection locking rather than discrete phase shifters saves a number of components. Such a device would cost about \$12 in silicon at prototype prices, provide half a month of battery life on two alkaline AAA cells, We demonstrate this form factor because, superficially, there are fewer people than there are places. But is such a device really necessary or useful? Is it sufficiently superior to a fiber mask to justify spending energy developing it? It has the advantage of being self-cleaning; and hair, eyes; a hand brought near the face is immediately sterilized. On the other hand, a personal device may present issues with participation and production volume. Interference If HFSS or ADS are not available, coupled SPICE-FDTD methods appear to be particularly simple and effective for these types of problems. The advantage of the phased array is in the free-space power combining and the near-field focusing. In our crude experiments, the loss tangent and poor impedance control of inexpensive substrates did not appear to pose a problem in itself; standard FR-4 or even PET substrate and screen-printed metal techniques seen in high-volume RFID tag production may be of some use. However, the Q factor of tuning elements on such lossy materials appears to be too high to form useful oscillators. Air-dielectric coaxial, Barium titanate dielectric slab resonators, or various types of substrate-independent resonators may all be suitable for this purpose. {\color{red} \} speculation } %\end{multicols} %\clearpage %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %{\Large Interference}\\ %\begin{multicols}{1} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %{\Large Mass production} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % %Almost all components on the device can be replicated with fully vertically-integrated first-principles. Capacitors can be % %If this 'electromagnetic mask' form is the ideal (not nearly), % %The largest RFID plants can produce % %a minimum of 5 GaAs or SiGe:C transistors will be required. Without SOI or, it does not appear that % %As a lower bound, there are 1 million hospital beds in the U.S. [AHA 2018]; and as an upper bound obtaining global herd immunity would take 1.75 billion units. % %It is difficult to determine the supply capacity for these semiconductor processes; information is not forthcoming from the manufacturers. Fermi estimates \footnote{GaAs MMIC market of \$2.2 Bn USD / random sample of MMIC prices = about 2 Bil devices / yr, 3e9 wifi connected devices produced each year,} % % % %It is possible to use common Si-based devices at these frequencies, especially with second-harmonic techniques [Winch 1982]. However, obtaining the required gain and output power is not a trivial matter. % %The techniques and equipment required to produce these devices are extremely complex; load-lock UHV, % % %Figures are not forthcoming, % %Given the supply difficulties of comparatively simple materials such as Tyvek at pandemic scales, it is difficult to imagine that RF semiconductor production can be immediately re-tasked and scaled to this degree. % %\paragraph{\textbf{Vacuum RF triode}}\ % % % %Especially combined with an integrated titanium sorption pump, % %One concern is the large filament heater power, which prevents the use of low-cost button cells for power. Use of cold-cathode field-emitter arrays would alleviate this issue, but at the cost of complexity. % %Small tungsten incandescent lights are available down to 0.05 watts. With a suitable high-efficiency cathode coating, a pulsed heater power of less than 0.02 % % % %\end{multicols} % % %The X-band is also minimally absorbed by air, allowing action in the far-field and scaling to square-kilometer areas with single installations. % % % % %\clearpage % \end{document}
\clearpage \subsection{Program} % (fold) \label{sub:program} In most software projects the top level \emph{artefact} you are aiming to create is a \textbf{program}. Within your software a program is a list of instructions the computer will perform when that program is run on the computer. When you create a program in your code you should be thinking about the tasks you want the program to achieve, and the steps you must get the computer to perform when the program is run. These then become the instructions within the program, with each instruction being a \nameref{sub:statement} of what you want performed. \begin{figure}[h] \centering \includegraphics[width=\textwidth]{./topics/program-creation/diagrams/BasicProgramConcept} \caption{A program contains instructions that command the computer to perform actions} \label{fig:program-creation-program} \end{figure} \mynote{ \begin{itemize} \item A program is an \textbf{artefact}, something you can create in your code. \item Figure \ref{fig:program-creation-program} shows the concepts related to the program's code. \item A program is a programming artefact used to define the steps to perform when the program is run. \item You use a compiler to convert the program's source code into an executable file. \item By declaring a program in your code you are telling the compiler to create a file the user can run (execute). \item The program has an \textbf{entry point} that indicates where the program's instructions start. \item The name of the program determines the name of the executable file. \item Your program can use code from a \nameref{sub:library} or number of libraries. \item In programming terminology, an instruction is called a \nameref{sub:statement}. \end{itemize} } % section program (end)
\section{Introduction} \label{sec:introduction} The cloud is changing how users store and access data. This is true for both legacy applications that are migrating local data into the cloud, and for emerging cloud-hosted applications that use a combination of content distribution networks (CDNs) and client-side local storage to achieve scalability. In both cases, the goal is to compose existing storage and caching services to implement scalable storage for the application. However, the challenges in doing so are to keep data consistent, keep the storage layer secure, and enforce storage policies across services. This paper presents \Syndicate, a wide-area storage system that meets these challenges in a general, coherent manner. There are two reasons to compose existing services to implement scalable storage. First, if we factor a scalable storage system by the capabilities of existing services, it is interesting to ask what extra functionality is needed, and how is it best provided? Our strategy is to use cloud storage for durability and scalable capacity, edge caches (CDNs and caching proxies) for scalable read bandwidth and reduced upstream load, and local storage for fast, possibly offline access. Once these capabilities are met, the remaining desirable functionality is wide-area consistency, storage layer security, and storage policy enforcement. \Syndicate\ introduces a new Metadata Service and storage middleware that provides this functionality in a general, configurable way. The second reason is that leveraging existing services is more than just taking advantage of someone having already implemented the corresponding functionality. More importantly, doing so also leverages a globally-deployed and professionally-operated instantiation of that functionality. Deploying and operating a global service, even with the availability of geographically distributed VMs, is an onerous task. \Syndicate\ side-steps that problem by using existing storage and caches, and in the process, significantly lowers the barrier-to-entry to constructing a customized, global storage service. The thorniest problem \Syndicate\ faces is contending with the weak consistency offered by edge caches. Namely, the cache operator, not the application, ultimately decides what constitutes ``stale'' data for eviction purposes, making it difficult to rely on cache control directives. Rather than trying to avoid caches, we intentionally incorporate them into the solution due to the tangible benefits they offer. Already, enterprises deploy on-site caching proxies to accelerate Web access for users, content providers employ global CDNs to distribute content to millions of readers, and ISPs deploy CDNs in their access networks to avoid transferring frequently-requested data over expensive links ~\cite{akamai,coralcdn,coblitz}. Our key insight into composing existing storage and caching services is that we should {\it avoid} treating them as first-class components. Instead, we must treat them as interchangeable utilities, distinguishable only by how well they provide their unique capabilities. Then, applications select services arbitrarily, and layer consistency, security, and policies ``on top'' of them with \Syndicate. By doing so, we provide them a virtual cloud storage service. Our key contribution is a novel consistency protocol, employed in both the data plane and control plane, that achieves this end. With this protocol, \Syndicate\ overcomes the weak consistency of edge caches in the data plane while continuing to leverage the benefits they offer. It also lets \Syndicate\ leverage caches in the control plane to scalably distribute certificates and signed executable code to middleware end-points, in order to secure the data plane and enforce data storage policies in a trusted manner.
\subsection{Ay-Matak} \label{sec:specie-ay-matak} \includegraphics[width=\linewidth]{bird_race_f_concept_by_luigiix-d52w3as} \begin{redtable}{\linewidth}{@{}L{.35}@{}L{.65}@{}} \textbf{Singular} & Matak\\ \textbf{Plural} & Ay-Matak\\ \textbf{Adjective} & Matakian\\ \textbf{Height} & 135-170cm\\ \textbf{Weight} & 45-65kg\\ \textbf{Gender Ratio} & 40\% Male / 60\% Female\\ \textbf{Reproduction} & Oviparity (Eggs)\\ \textbf{Maturity} & 15 years\\ \textbf{Lifespan} & 75 years\\ \textbf{Language} & Kitabian\\ \textbf{Diet} & Omnivore\\ \textbf{Homeworld} & Kitaba (Lost)\\ \textbf{\hyperref[sec:sector-atb]{ATB preference}} & \hyperref[sec:sector-atb]{B-W-H} \end{redtable} The Ay-Matak are an avian-like alien species from the world of Kitaba. They were one of the founding races of a Federation that spanned the galaxy before the Surge, renowned for being itinerant wanderers and creative artists. Matakian society focused on culture over conquest, but did not shy away from confrontation when it became unavoidable. To create a Matak character, please refer to the \textit{\hyperref[sec:rules-creation]{Character creation section}} \begin{genericsection}{Background} Kitaba was rumoured to have a tall, dense forest that covered the entire planet and boasted a rich and diverse ecosystem. An overabundance of resources meant that the Ay-Matak had little need to compete with each other. Matakian society evolved to compete culturally rather than physically, leading to a rich and complex history of artistic endeavour. Arts that use an abundance of colour or visual stimuli are especially valued by the Ay-Matak.\\ Matakian governance also revolved around artistic endeavour, with their leaders usually a person of great cultural importance. Democracy was usually limited to recognizing the cultural importance of an individual. Once a Matak achieved that recognition they were able to join the select few who governed and directed Matakian society. \end{genericsection} \begin{genericsection}{Physiology} Ay-Matak are typically shorter and lighter than other bipedal humanoids. They have two pairs of wings that enable them to fly, but they have a pair of functional legs that they use to walk on the ground. Their beak is solid and sharp along the sides, but the tip is made out of softer material so that is flexible enough to produce a variety of sounds.\\ The feathers of a male Matak is always more colourful than the female. Females are usually only limited to whites, greys and blacks. \end{genericsection} \begin{genericsection}{Male Names} Andomion, Antakon, Artenaeon, Demoleo, Dralop, Entardion, Eraton, Eratro, Heliodo, Ikotu, Kalipon, Koron, Lokinu, Melaleimon, Myrodon, Panolio, Taramio, Teladon, Tridru, Tyrorion \end{genericsection} \begin{genericsection}{Female Names} Agara, Alanie, Aldorria, Anakia, Atria, Bellaleta, Belliana, Hallia, Iripira, Karellia, Katia, Kynie, Laleta, Nerian, Nolanta, Obemona, Peneleta, Talitian, Tiakia, Utriema \end{genericsection} \begin{genericsection}{Secondary Names} Ay-Matak do not take family names, but instead earn cultural "\textit{titles}" for their last well-known greatest achievement. For example, \textit{Andomion, painter of 'Matak Lost'}. Those without a great achievement usually go by their occupation, birthplace, spacecraft name, or include the name of their mother ("\textit{hatchling of Anakia}"). \end{genericsection}
\problemname{Kitesurfing} Nora the kitesurfer is taking part in a race across the Frisian islands, a very long and thin archipelago in the north of the Netherlands. The race takes place on the water and follows a straight line from start to finish. Any islands on the route must be jumped over -- it is not allowed to surf around them. The length of the race is $s$ metres and the archipelago consists of a number of non-intersecting intervals between start and finish line. During the race, Nora can move in two different ways: \begin{enumerate} \item Nora can \emph{surf} between any two points at a speed of $1$ metre per second, provided there are no islands between them. \item Nora can \emph{jump} between any two points if they are at most $d$ metres apart and neither of them is on an island. A jump always takes $t$ seconds, regardless of distance covered. \end{enumerate} While it is not possible to land on or surf across the islands, it is still allowed to visit the end points of any island. \vspace{-2mm} \begin{figure}[!h] \centering \includegraphics[width=0.8\textwidth]{samples} \caption{Illustration of the two sample cases.} \end{figure} Your task is to find the shortest possible time Nora can complete the race in. You may assume that no island is more than $d$ metres long. In other words it is always possible to finish the race. \vspace{-2mm} \section*{Input} The input consists of: \begin{itemize} \item One line with three integers $s,d$ and $t$ ($1 \le s,d,t \le 10^9$), where $s$ is the length of the race in metres, $d$ is the maximal jump distance in metres, and $t$ is the time needed for each jump in seconds. \item One line with an integer $n$ ($0 \le n \le 500$), the number of islands. \item $n$ lines, the $i$th of which contains two integers $\ell_i$ and $r_i$ ($0 < \ell_i < r_i < s$ and $r_i-\ell_i \le d$), giving the boundaries of the $i$th island in metres, relative to the starting point. \end{itemize} The islands do not touch and are given from left to right, that is $r_i < \ell_{i+1}$ for each valid $i$. \vspace{-2mm} \section*{Output} Output one number, the shortest possible time in seconds needed to complete the race. It can be shown that this number is always an integer.
\documentclass[12pt]{article} \usepackage{float} \usepackage{enumitem} \usepackage{graphicx} \usepackage{hyperref} \hypersetup{ colorlinks=true, urlcolor=blue } \setlength{\parskip}{1ex} \setlength{\parindent}{0pt} \addtolength{\evensidemargin}{-0.625in} \addtolength{\oddsidemargin}{-0.625in} \addtolength{\textwidth}{1.25in} \addtolength{\topmargin}{-0.625in} \addtolength{\textheight}{1.25in} \begin{document} \begin{center} \Huge\bf INFO30005 Deliverable 1 \end{center} \subsection*{Group Details} Group Name: \textit{Pixels}\par Tutor: \textit{Priyankar Bhattacharjee}\par Tutorial: \textit{Wednesday 12pm-1pm}\par Members: \vspace{-2ex} \begin{itemize}[noitemsep] \item \textit{Jeff Li 1044965} \item \textit{Alisa Blakeney 1178580} \item \textit{Noah Stammbach 1182954} \item \textit{Minh Hoang Phan 1068112} \end{itemize} \subsection*{Links} Link to Prototype(mobile): {\small\url{https://www.figma.com/proto/NWu2ItK5AM0H7M0C9MGh5Q/Assignment-1?node-id=16%3A4&starting-point-node-id=16%3A4}}\\ Link to Prototype(desktop): {\small\url{https://www.figma.com/proto/NWu2ItK5AM0H7M0C9MGh5Q/Assignment-1?node-id=177%3A62&scaling=scale-down&page-id=0%3A1&starting-point-node-id=34%3A22&show-proto-sidebar=1}}\\ Link to complete Figma file:{\small\url{https://www.figma.com/file/NWu2ItK5AM0H7M0C9MGh5Q/Assignment-1?node-id=1\%3A11}}\\ Link to GitHub Repository: {\small\url{https://github.com/alisay/Diabetes-Home}} \newpage \subsubsection*{Figma Screenshot: Patient App, no connections} \begin{figure}[H] \centering \includegraphics[width=.8\textwidth]{patient_nolines} \end{figure} \subsubsection*{Figma Screenshot: Patient App, with connections} \begin{figure}[H] \centering \includegraphics[width=.8\textwidth]{patient_lines} \end{figure}\newpage \subsubsection*{Figma Screenshot: Clinician App, no connections} \begin{figure}[H] \centering \includegraphics[width=.8\textwidth]{desktop_nolines} \end{figure} \subsubsection*{Figma Screenshot: Clinician App, with connections} \begin{figure}[H] \centering \includegraphics[width=.8\textwidth]{desktop_lines} \end{figure} \end{document}
\chapter{PLDatabase} \paragraph{Motivation} The reason for creating \emph{PLDatabase} was to have a minimalistic and universal interface to work with databases. Instead of implementing an own database system we use a backend design pattern to use already available common implementations like \emph{SQLite}. \paragraph{External Dependences} PLDatabase only depends on the \textbf{PLCore} library and doesn't use any external third party libraries itself. % Include the other sections of the chapter \input{PLDatabase/Database} \cleardoublepage \input{PLDatabase/DatabaseBackends} \cleardoublepage
\chapter{Debugging Techniques} There are numerous methods ROSE provides to help debug the development of specialized source-to-source translators. This section shows some of the techniques for getting information from IR nodes and displaying it. More information about generation of specialized AST graphs to support debugging can be found in chapter \ref{Tutorial:chapterGeneralASTGraphGeneration} and custom graph generation in section \ref{Tutorial:chapterCustomGraphs}. \section{Input For Examples Showing Debugging Techniques} Figure~\ref{Tutorial:exampleInputCode_ExampleDebugging} shows the input code used for the example translators that report useful debugging information in this chapter. \begin{figure}[!h] {\indent {\mySmallFontSize % Do this when processing latex to generate non-html (not using latex2html) \begin{latexonly} \lstinputlisting{\TutorialExampleDirectory/inputCode_ExampleDebugging.C} \end{latexonly} % Do this when processing latex to build html (using latex2html) \begin{htmlonly} \verbatiminput{\TutorialExampleDirectory/inputCode_ExampleDebugging.C} \end{htmlonly} % end of scope in font size } % End of scope in indentation } \caption{Example source code used as input to program in codes showing debugging techniques shown in this section.} \label{Tutorial:exampleInputCode_ExampleDebugging} \end{figure} \section{Generating the code from any IR node} Any IR node may be converted to the string that represents its subtree within the AST. If it is a type, then the string will be the value of the type; if it is a statement, the value will be the source code associated with that statement, including any sub-statements. To support the generation for strings from IR nodes we use the {\tt unparseToString()} member function. This function strips comments and preprocessor control structure. The resulting string is useful for both debugging and when forming larger strings associated with the specification of transformations using the string-based rewrite mechanism. Using ROSE, IR nodes may be converted to strings, and strings converted to AST fragments of IR nodes. Note that unparsing associated with generating source code for the backend vendor compiler is more than just calling the unparseToString member function, since it introduces comments, preprocessor control structure and formating. Figure~\ref{Tutorial:exampleDebuggingIRNodeToString} shows a translator which generates a string for a number of predefined IR nodes. Figure~\ref{Tutorial:exampleInputCode_ExampleDebugging} shows the sample input code and figure~\ref{Tutorial:exampleOutput_DebuggingIRNodeToString} shows the output from the translator when using the example input application. \begin{figure}[!h] {\indent {\mySmallFontSize % Do this when processing latex to generate non-html (not using latex2html) \begin{latexonly} \lstinputlisting{\TutorialExampleDirectory/debuggingIRnodeToString.C} \end{latexonly} % Do this when processing latex to build html (using latex2html) \begin{htmlonly} \verbatiminput{\TutorialExampleDirectory/debuggingIRnodeToString.C} \end{htmlonly} % end of scope in font size } % End of scope in indentation } \caption{Example source code showing the output of the string from an IR node. The string represents the code associated with the subtree of the target IR node.} \label{Tutorial:exampleDebuggingIRNodeToString} \end{figure} \begin{figure}[!h] {\indent {\mySmallFontSize % Do this when processing latex to generate non-html (not using latex2html) \begin{latexonly} \lstinputlisting{\TutorialExampleBuildDirectory/debuggingIRnodeToString.out} \end{latexonly} % Do this when processing latex to build html (using latex2html) \begin{htmlonly} \verbatiminput{\TutorialExampleBuildDirectory/debuggingIRnodeToString.out} \end{htmlonly} % end of scope in font size } % End of scope in indentation } \caption{Output of input code using debuggingIRnodeToString.C} \label{Tutorial:exampleOutput_DebuggingIRNodeToString} \end{figure} \section{Displaying the source code position of any IR node} This example shows how to obtain information about the position of any IR node relative to where it appeared in the original source code. New IR nodes (or subtrees) that are added to the AST as part of a transformation will be marked as part of a transformation and have no position in the source code. Shared IR nodes (as generated by the AST merge mechanism are marked as shared explicitly (other IR nodes that are shared by definition don't have a SgFileInfo object and are thus not marked explicitly as shared. The example translator to output the source code position is shown in figure~\ref{Tutorial:exampleDebuggingSourceCodePositionInformation}. Using the input code in figure~\ref{Tutorial:exampleInputCode_ExampleDebugging} the output code is shown in figure~\ref{Tutorial:exampleOutput_DebuggingIRNodeToString}. \begin{figure}[!h] {\indent {\mySmallFontSize % Do this when processing latex to generate non-html (not using latex2html) \begin{latexonly} \lstinputlisting{\TutorialExampleDirectory/debuggingSourceCodePositionInformation.C} \end{latexonly} % Do this when processing latex to build html (using latex2html) \begin{htmlonly} \verbatiminput{\TutorialExampleDirectory/debuggingSourceCodePositionInformation.C} \end{htmlonly} % end of scope in font size } % End of scope in indentation } \caption{Example source code showing the output of the string from an IR node. The string represents the code associated with the subtree of the target IR node.} \label{Tutorial:exampleDebuggingSourceCodePositionInformation} \end{figure} \begin{figure}[!h] {\indent {\mySmallFontSize % Do this when processing latex to generate non-html (not using latex2html) \begin{latexonly} \lstinputlisting{\TutorialExampleBuildDirectory/debuggingSourceCodePositionInformation.out} \end{latexonly} hared IR nodes (as generated by the AST merge mechanism are mar % Do this when processing latex to build html (using latex2html) \begin{htmlonly} \verbatiminput{\TutorialExampleBuildDirectory/debuggingSourceCodePositionInformation.out} \end{htmlonly} % end of scope in font size } % End of scope in indentation } \caption{Output of input code using debuggingSourceCodePositionInformation.C} \label{Tutorial:exampleOutput_DebuggingIRNodeToString} \end{figure}
\subsection{Rank Predictor} We have dubbed our working project \textit{Rank Predictor}. It contains things such as the implementation of ML models, dataset loader and pipeline, analysis scripts, and training orchestration scripts. Opposed to the GN code it is not a library but rather a loose collection of scripts and classes. In combination with the dataset it may be used to reproduce our results. In this section we describe the individual components on a high level, enriched with noteworthy details. \begin{itemize} \item \textbf{Analysis}: Scripts and Jupyter notebooks for post-training analysis of model weights, activations, etc. \item \textbf{Data}: The subfolders \texttt{data/v1} and \texttt{data/v2} contain code related to both dataset versions, respectively. For each dataset we define a class (\texttt{DatasetV1} and \texttt{DatasetV2}) which extends PyTorch's dataset class \texttt{torch.utils.data.Dataset}. The datasets only hold a list of all files in RAM and load the samples (images and the graph JSON file) on the fly, once a sample is requested. The dataset classes may be reused by researchers who want to work with our dataset as well.\\ We split our datasets with the method \texttt{get\_threefold}. It deterministically splits the dataset on program-startup. The source code is written down in Listing \ref{lst:getthreefold}.\\ For dataset version 2 there are two subclasses inheriting from \texttt{DatasetV2}, namely \texttt{DatasetV2Screenshots} and \texttt{DatasetV2Cached}. The former discards all graph information and yields lists of screenshots instead. The latter serves graphs where the nodes are attributed with cached feature vectors, previously computed by a feature extractor model. \item \textbf{ML models}: Our ML models are in the \texttt{model} subfolder. Each model is a class inheriting from \texttt{torch.nn.Module} with its own file. For GNs there are common implementations of aggregation and update functions which we place in the model folder as well. \item \textbf{Trainer}: Orchestration of training runs. We use TensorBoard to monitor training runs and Sacredboard to log experiments. Our \texttt{TraininRun} class is generic and calls an abstract \texttt{\_train\_step} method for each training step. After several steps it calls \texttt{\_run\_valid} with both train and test dataset to see how well the model performs on those dataset in evaluation mode (dropout disabled). We implement this class for GN training, feature extractor pre-training, and training on dataset version 1. The trainer folder also contains the probabilistic ranking loss (defined in Section~\ref{sec:loss}) and accuracy metric function (defined in Section~\ref{sec:accuracy}). We have unit tested the critical functions. \end{itemize}
\documentclass[11pt]{article} \usepackage[utf8]{inputenc} \usepackage[english]{babel} \usepackage{hyperref} \usepackage{listings} %for dotex \usepackage[pdftex]{graphicx} \usepackage[pdf]{graphviz} \usepackage[boxed]{algorithm2e} %end for dote \usepackage{color} \usepackage{morewrites} \title{Multi Tenancy to Completion} \begin{document} \maketitle \section{The Problem} FoxCommerce platform has been moving towards multi-tenancy and is almost there. There are a couple of remaining issues that need to be addressed for the system to be completely multi tenant. \section{What We Have} \subsection{Organizations} We have a model of organizations which have roles and permissions and users. Organizations are associated with a specific scope. Scopes provide a way to organize data hierarchically and limit access. \subsubsection{Capabilities and Constraints} \paragraph{Organizations can...} \begin{enumerate} \item Control roles and permissions. \item Control how a scope is accessed. \item Have sub organizations that belong to subscopes. \item Control subscopes. \end{enumerate} \paragraph{Organizations cannot...} \begin{enumerate} \item Cross sibling scopes. \item Have unscoped data. \item Users cannot log into multiple scopes at same time. \end{enumerate} \subsection{Scopes} Almost all tables in the system have a scope column. Scopes are hierarchical organization of data like a filesystem tree. Users with access to a scope do not have access to the parent scope. \digraph[scale=0.80]{Scopes}{ splines="ortho"; rankdir=LR; node [shape=box,style=filled,fillcolor="lightblue"]; subgraph zero{ tenant [shape=record, label="Tenant (1)"] }; subgraph first{ merchant1 [shape=record,label="{Merchant A(1.2)}"]; merchant2 [shape=record,label="{Merchant B(1.3)}"]; }; tenant -> merchant1 tenant -> merchant2 } Each merchant may have one or more storefronts. The question of whether the data of those storefronts is scoped depends on the use cases we want to enable. Is a different organization managing the other store fronts? Then we probably want this \digraph[scale=0.80]{Storefronts}{ splines="ortho"; rankdir=LR; node [shape=box,style=filled,fillcolor="lightblue"]; subgraph zero{ tenant [shape=record, label="Tenant (1)"] }; subgraph first{ merchant1 [shape=record,label="{Merchant A(1.2)}"]; merchant2 [shape=record,label="{Merchant B(1.3)}"]; }; subgraph third { storefront1 [shape=record,label="{Storefront A1(1.2.4?)}"]; storefront2 [shape=record,label="{Storefront A2(1.2.5?)}"]; storefront3 [shape=record,label="{Storefront B(1.3.6?)}"]; }; tenant -> merchant1 tenant -> merchant2 merchant1 -> storefront1 merchant1 -> storefront2 merchant2 -> storefront3 } Is the same organization managing various storefronts? Then we want this. \digraph[scale=0.80]{Storefronts}{ splines="ortho"; rankdir=LR; node [shape=box,style=filled,fillcolor="lightblue"]; subgraph zero{ tenant [shape=record, label="Tenant (1)"] }; subgraph first{ merchant1 [shape=record,label="{Merchant A(1.2)}"]; merchant2 [shape=record,label="{Merchant B(1.3)}"]; }; subgraph third { storefront1 [shape=record,label="{Storefront A1(1.2)}"]; storefront2 [shape=record,label="{Storefront A2(1.2)}"]; storefront3 [shape=record,label="{Storefront B(1.3)}"]; }; tenant -> merchant1 tenant -> merchant2 merchant1 -> storefront1 merchant1 -> storefront2 merchant2 -> storefront3 } Notice that the scope of the storefronts is the same. Regardless if we have one organization or another we need a different organizing structure for storefront data that is separate from scopes. We want a model of channels. \subsubsection{Capabilities and Constraints} \paragraph{Scopes can...} \begin{enumerate} \item Group data like a directory in a filesystem. \item Control access to data via roles/permissions that are in that scope. \end{enumerate} \paragraph{Scopes cannot...} \begin{enumerate} \item Share data with sibling scopes. \item Provide semantic relationships between data in a scope. \item Provide semantic relationships between data in different scopes. \end{enumerate} \subsection{Views (formally Context)} All merchandising information can have several views. Views provide a way to change the information of a product, sku, discount, or other merchandising data for a specific purpose. For example, each storefront could possibly have a different view of a product. A review/approval flow may have it's own view. \digraph[scale=0.80]{Views}{ splines="ortho"; rankdir=LR; node [shape=record,style=filled,fillcolor="lightblue"]; subgraph zero{ product [label="Product"] }; subgraph first{ view1 [label="{View for Storefront A}"]; view2 [label="{View for Storefront B}"]; view3 [label="{View for Review/Approval}"]; }; product -> view1 product -> view2 product -> view3 } \subsubsection{Capabilities and Constraints} \paragraph{Views can...} \begin{itemize} \item Control which versions of data in the object store are displayed. \item Act as a git branch on the merchandising data. \item Commits provide branching history between views. \end{itemize} \paragraph{Views cannot...} \begin{itemize} \item Control access to data. \item Shared between sibling scopes. \item Cannot control versions of parts of objects. \item Cannot describe semantic relationships between views. \end{itemize} \section{What We Need} \subsection{Catalogs} Catalogs are collections of products you want to sell. \digraph[scale=0.80]{Catalogs}{ splines="ortho"; rankdir=LR; node [shape=box,style=filled,fillcolor="tan"]; subgraph zero{ catalog [label="Catalog"] }; subgraph first{ scope [label="Scope"]; products [label="Products"]; discounts [label="Discounts"]; name [label="Name"]; country [label="Country"]; language [label="Language"]; live [label="Live View"]; stage [label="Stage View"]; }; catalog -> scope [label="belongs to"] catalog -> name [label="has a"] catalog -> products [label="has"] catalog -> discounts [label="has"] catalog -> payment [label="has"] catalog -> country [label="for a"] catalog -> language [label="has default"] catalog -> live [label="points to"] catalog -> stage [label="points to"] } \subsection{Channels} Channels should be comprised of three key components \digraph[scale=0.80]{Channels}{ splines="ortho"; rankdir=LR; node [shape=box,style=filled,fillcolor="tan"]; subgraph zero{ channel [label="Channel"] }; subgraph first{ scope [label="Scope"]; catalog [label="Catalog"]; payment [label="Payment Methods"]; stock [label="Stock"]; aux [label="Auxiliary Data..."]; }; channel -> scope [label="belongs to"] channel -> catalog [label="has a"] channel -> payment [label="uses"] channel -> stock [label="has"] channel -> aux [label="has"] } \subsection{Storefronts} A storefront is a website that can sell products from a catalog. A storefront uses a channel in addition to data from the CMS. \digraph[scale=0.80]{StorefrontModel}{ splines="ortho"; rankdir=LR; node [shape=box,style=filled,fillcolor="tan"]; subgraph zero{ store [label="Storefront(Channel)"] }; subgraph first{ scope [label="Scope"]; channel [label="Channel"]; live [label="Live CMS View"]; stage [label="Stage CMS View"]; host [label="Host"]; }; store -> scope [label="belongs to"] store -> channel [label="uses"] store -> live [label="shows"] store -> stage [label="points to"] store -> host [label="serves from"] } \newpage \subsection{Back to Organizations} Once we have these new models we can assign them to organizations \digraph[scale=0.80]{OrgModel}{ splines="ortho"; rankdir=TD; node [shape=box,style=filled,fillcolor="tan"]; subgraph zero{ rank=source; org [label="Organization"] }; subgraph first{ scope [label="Scope 1.2"] }; subgraph second{ rank=same; catalog [label="Master Catalog"]; view [label="Master View"]; }; subgraph third{ view1 [label="View A"]; view2 [label="View B"]; }; subgraph fourth{ catalog1 [label="Catalog A"]; catalog2 [label="Catalog B"]; }; subgraph fifth{ channel1 [label="Channel A"]; channel2 [label="Channel B"]; }; subgraph sixth { rank=sink; store1 [label="Storefront A"]; store2 [label="Storefront B"]; }; org -> scope [label="belongs to"] scope -> catalog; scope -> view; catalog -> catalog1 catalog -> catalog2 view -> view1 [label="branch"]; view -> view2 [label="branch"]; view1 -> catalog1 view2 -> catalog2 catalog1 -> channel1 [label="uses"]; catalog2 -> channel2 [label="uses"]; store1 -> channel1 [label="used by"]; store2 -> channel2 [label="used by"]; } \subsection {Public Access} Our current public endpoints for searching the catalog, registering users, and viewing/purchasing products are not multi-tenant aware at the moment. We need to modify them to understand which channel they are serving. \digraph[scale=0.80]{Proxy}{ splines="ortho"; rankdir=TD; node [shape=record,style=filled,fillcolor="lightblue"]; client [label="Client"]; riverrock [label="River Rock Proxy"]; db [shape=note,label="DB"]; channel [label="Channel for host.com"]; catalog [label="Catalog"]; view [label="View"]; client -> riverrock [label="request host.com"] riverrock -> db [label="find channel"] db -> channel [label="found"]; channel -> view; channel -> catalog; view -> riverrock [label="serve"]; catalog -> riverrock [label="serve"]; } \section{Example Story} We acquired a customer which sells shoes called ShoeMe that wants to operate two global sites and sell products on amazon. They want to sell on two domains, shoeme.co.uk and shoeme.co.jp and amazon.com. \digraph[scale=0.80]{ShoeMe}{ splines="ortho"; rankdir=LR; node [shape=record,style=filled,fillcolor="pink"]; subgraph zero{ shoeme [label="ShoeMe"] }; subgraph first{ amazon [label="{amazon.com}"]; uk [label="{shoeme.co.jp}"]; jp [label="{shoeme.co.uk}"]; }; shoeme -> amazon; shoeme -> uk; shoeme -> jp; } We create a new \emph{Organization} called ShoeMe and \emph{Scope} with id ``1.2'' . Within that \emph{Organization} we create a \emph{role} called ``admin'' and a new \emph{user} assigned to that role. \digraph[scale=0.80]{ShoeMeOrg}{ splines="ortho"; rankdir=TD; node [shape=record,style=filled,fillcolor="pink"]; org [label="ShoeMe Org"] scope [label="Scope 1.2"]; admin [label="{Admin Role|Admin Users}"]; scope -> org; org -> admin; } The ShoeMe representative follows the password creation flow for their new account and gets access to ashes. We create for the customer four catalogs called ``master'', ``uk'', ``jp'', and ``amazon''. Behind the scenes with creates four views ``master'', ``uk'', ``jp'', and ``amazon''. They then import there products into the master catalog. They then use ashes to selectively assign products into the other three catalogs. This forks the products into the three other views. \digraph[scale=0.80]{ShoeMeCatalogs}{ splines="ortho"; rankdir=TD; node [shape=record,style=filled,fillcolor="pink"]; scope [label="{Scope 1.2}"]; master [fillcolor="green",label="{Master|{Catalog|View}}"]; subgraph catalogs { rank=same; uk [fillcolor="green",label="{UK|{Catalog|View}}"]; jp [fillcolor="green",label="{JP|{Catalog|View}}"]; amazon [fillcolor="green",label="{Amazon|{Catalog|View}}"]; }; scope -> master; master -> uk; master -> jp; master -> amazon; } We create three channels for the customer called ``uk''. ``jp''. and ``amazon'' and assign each appropriate catalog to the channels. \digraph[scale=0.80]{ShoeMeChannels}{ splines="ortho"; rankdir=TD; node [shape=record,style=filled,fillcolor="pink"]; scope [label="{Scope 1.2}"]; master [fillcolor="green",label="{Master|{Catalog|View}}"]; subgraph catalogs { rank=same; uk [fillcolor="green",label="{UK|{Catalog|View}}"]; jp [fillcolor="green",label="{JP|{Catalog|View}}"]; amazon [fillcolor="green",label="{Amazon|{Catalog|View}}"]; }; subgraph channels { rank=same; ukc [fillcolor="lightblue",label="{UK|{Channel|Stock}}"]; jpc [fillcolor="lightblue",label="{JP|{Channel|Stock}}"]; amazonc [fillcolor="lightblue",label="{Amazon|{Channel|Stock}}"]; }; scope -> master; master -> uk; master -> jp; master -> amazon; uk -> ukc; jp -> jpc; amazon -> amazonc; } We then create two storefronts, ``shoeme.co.uk'' and ``shoeme.co.jp''. Behind the scenes these two storefronts will create two views which will be used by the CMS to show various content. Just like with catalogs they can first build one storefront and then copy over the data into the other. \digraph[scale=0.80]{ShoeMeStores}{ splines="ortho"; rankdir=TD; node [shape=record,style=filled,fillcolor="pink"]; scope [label="{Scope 1.2}"]; master [fillcolor="green",label="{Master|{Catalog|View}}"]; subgraph catalogs { rank=same; uk [fillcolor="green",label="{UK|{Catalog|View}}"]; jp [fillcolor="green",label="{JP|{Catalog|View}}"]; amazon [fillcolor="green",label="{Amazon|{Catalog|View}}"]; }; subgraph channels { rank=same; ukc [fillcolor="lightblue",label="{UK|{Channel|Stock}}"]; jpc [fillcolor="lightblue",label="{JP|{Channel|Stock}}"]; amazonc [fillcolor="lightblue",label="{Amazon|{Channel|Stock}}"]; }; subgraph storefronts { rank=same; uks [fillcolor="yellow",label="{shoeme.co.uk|{Storefront|CMS View}}"]; jps [fillcolor="yellow",label="{shoeme.co.jp|{Storefront|CMS View}}"]; }; scope -> master; master -> uk; master -> jp; master -> amazon; uk -> ukc; jp -> jpc; amazon -> amazonc; ukc -> uks; jpc -> jps; } Our API will understand how to serve traffic depending on the host of each storefront by selecting the appropriate CMS views and catalog assigned to the storefront. Behind the scenes will can also provide sister views to each view for staging changing which await approval. Each catalog may also be assigned the same or different stock item location and pricing information. Each catalog can therefore share or maintain separate stock for the products in the catalog. \end{document}
% ********************************************************************** % Author: Ajahn Chah % Translator: % Title: Tuccho Pothila % First published: Living Dhamma % Comment: An informal talk given at Ajahn Chah's kuti, to a group of laypeople, one evening in 1978 % Copyright: Permission granted by Wat Pah Nanachat to reprint for free distribution % ********************************************************************** % Notes on the text: % This talk has been published elsewhere under the title `Tuccho Pothila -- Venerable Empty-Scripture' % ********************************************************************** \chapterFootnote{\textit{Note}: This talk has been published elsewhere under the title: `\textit{Tuccho Pothila -- Venerable Empty-Scripture}'} \chapter{Tuccho Pothila} \index[general]{supporting!through material things} \dropcaps{T}{here are two ways} to support Buddhism. One is known as \pali{\=amisap\=uj\=a}, supporting through material offerings: the four requisites of food, clothing, shelter and medicine. There material offerings are given to the Sa\.ngha of monks and nuns, enabling them to live in reasonable comfort for the practice of Dhamma. This fosters the direct realization of the Buddha's teaching, in turn bringing continued prosperity to the Buddhist religion. \index[similes]{tree!kamma} \index[similes]{tree!Buddhism} Buddhism can be likened to a tree. A tree has roots, a trunk, branches, twigs and leaves. All the leaves and branches, including the trunk, depend on the roots to absorb nutriment from the soil. Just as the tree depends on the roots to sustain it, our actions and our speech are like `branches' and `leaves', which depend on the mind, the `root', absorbing nutriment, which it then sends out to the `trunk', `branches' and `leaves'. These in turn bear fruit as our speech and actions. Whatever state the mind is in, skilful or unskilful, it expresses that quality outwardly through our actions and speech. \index[general]{supporting!through practising well} \index[general]{practice!as an offering} \looseness=1 Therefore, the support of Buddhism through the practical application of the teaching is the most important kind of support. For example, in the ceremony of determining the precepts on observance days, the teacher describes those unskilful actions which should be avoided. But if you simply go through this ceremony without reflecting on their meaning, progress is difficult and you will be unable to find the true practice. The real support of Buddhism must therefore be done through \pali{\glsdisp{patipatti}{pa\d{t}ipattip\=uj\=a,}} the `offering' of practice, cultivating true restraint, concentration and wisdom. Then you will know what Buddhism is all about. If you don't understand through practice, you still won't know, even if you learn the whole \glsdisp{tipitaka}{Tipi\d{t}aka.} In the time of the Buddha there was a monk known as Tuccho Pothila. Tuccho Pothila was very learned, thoroughly versed in the scriptures and texts. He was so famous that he was revered by people everywhere and had eighteen monasteries under his care. When people heard the name `Tuccho Pothila' they were awe-struck and nobody would dare question anything he taught, so much did they revere his command of the teachings. Tuccho Pothila was one of the Buddha's most learned disciples. \index[general]{practice!vs. study} One day he went to pay respects to the Buddha. As he was paying his respects, the Buddha said, `Ah, hello, Venerable Empty Scripture!' Just like that! They conversed for a while until it was time to go, and then, as he was taking leave of the Buddha, the Buddha said, `Oh, leaving now, Venerable Empty Scripture?' \index[general]{sama\d{n}a!real} That was all the Buddha said. On arriving, `Oh, hello, Venerable Empty Scripture.' When it was time to go, `Ah, leaving now, Venerable Empty Scripture?' The Buddha didn't expand on it, that was all the teaching he gave. Tuccho Pothila, the eminent teacher, was puzzled, `Why did the Buddha say that? What did he mean?' He thought and thought, turning over everything he had learned, until eventually he realized, `It's true! Venerable Empty Scripture -- a monk who studies but doesn't practise.' When he looked into his heart he saw that really he was no different from laypeople. Whatever they aspired to he also aspired to, whatever they enjoyed he also enjoyed. There was no real \pali{\glsdisp{samana}{`sama\d{n}a'}} within him, no truly profound quality capable of firmly establishing him in the Noble Way and providing true peace. So he decided to practise. But there was nowhere for him to go to. All the teachers around were his own students, no-one would dare accept him. Usually when people meet their teacher they become timid and deferential, and so no-one would dare become his teacher. \index[general]{practice!with sincerity} Finally he went to see a certain young novice, who was enlightened, and asked to practise under him. The novice said, `Yes, sure you can practise with me, but only if you're sincere. If you're not sincere then I won't accept you.' Tuccho Pothila pledged himself as a student of the novice. The novice then told him to put on all his robes. Now there happened to be a muddy bog nearby. When Tuccho Pothila had neatly put on all his robes, expensive ones they were, too, the novice said, `Okay, now run down into this muddy bog. If I don't tell you to stop, don't stop. If I don't tell you to come out, don't come out. Okay, run!' Tuccho Pothila, neatly robed, plunged into the bog. The novice didn't tell him to stop until he was completely covered in mud. Finally he said, `You can stop, now' so he stopped. `Okay, come out now!' and so he \mbox{came out.} This clearly showed the novice that Tuccho Pothila had given up his pride. He was ready to accept the teaching. If he wasn't ready to learn he wouldn't have run into the bog like that, being such a famous teacher, but he did it. The young novice, seeing this, knew that Tuccho Pothila was sincerely determined to practise. \index[similes]{lizard in a termite mound!sense restraint} When Tuccho Pothila had come out of the bog, the novice gave him the teaching. He taught him to observe the sense objects, to know the mind and to know the sense objects, using the simile of a man catching a lizard hiding in a termite mound. If the mound had six holes in it, how would he catch it? He would have to seal off five of the holes and leave just one open. Then he would have to simply watch and wait, guarding that one hole. When the lizard ran out he could catch it. \index[general]{clear comprehension!description of} Observing the mind is like this. Closing off the eyes, ears, nose, tongue and body, we leave only the mind. To `close off' the senses means to restrain and compose them, observing only the mind. Meditation is like catching the lizard. We use \glsdisp{sati}{sati} to note the breath. Sati is the quality of recollection, as in asking yourself, `What am I doing?' \pali{\glsdisp{sampajanna}{Sampaja\~n\~na}} is the awareness that `now I am doing such and such'. We observe the in and out breathing with sati and \pali{sampaja\~n\~na}. This quality of recollection is something that arises from practice, it's not something that can be learned from books. Know the feelings that arise. The mind may be fairly inactive for a while and then a feeling arises. Sati works in conjunction with these feelings, recollecting them. There is sati, the recollection that `I will speak', `I will go', `I will sit' and so on, and then there is \pali{sampaja\~n\~na}, the awareness that `now I am walking', `I am lying down', `I am experiencing such and such a mood.' With sati and \pali{sampaja\~n\~na}, we can know our minds in the present moment and we will know how the mind reacts to sense impressions. \index[general]{sense objects!and the mind} That which is aware of sense objects is called `mind'. Sense objects `wander into' the mind. For instance, there is a sound, like the electric drill here. It enters through the ear and travels inwards to the mind, which acknowledges that it is the sound of an electric drill. That which acknowledges the sound is called `mind'. \index[general]{one who knows} \index[general]{knowledge and vision} Now this mind which acknowledges that sound is quite basic. It's just the average mind. Perhaps annoyance arises within the one who acknowledges. We must further train `the one who acknowledges' to become \glsdisp{one-who-knows}{`the one who knows'} in accordance with the truth -- known as \pali{\glsdisp{buddho}{Buddho.}} If we don't clearly know in accordance with the truth then we get annoyed at sounds of people, cars, electric drills and so on. This is just the ordinary, untrained mind acknowledging the sound with annoyance. It knows in accordance with its preferences, not in accordance with the truth. We must further train it to know with vision and insight, \pali{\~n\=a\d{n}adassana},\footnote{Literally: knowledge and insight (into the Four Noble Truths).} the power of the refined mind, so that it knows the sound as simply sound. If~we don't cling to sound there is no annoyance. The sound arises and we simply note it. This is called truly knowing the arising of sense objects. If we develop the \pali{Buddho}, clearly realizing the sound as sound, then it doesn't annoy us. It arises according to conditions, it is not a being, an individual, a self, an `us' or `them'. It's just sound. The mind lets go. \index[general]{one who knows} This knowing is called \pali{Buddho}, the knowledge that is clear and penetrating. With this knowledge we can let the sound simply be sound. It doesn't disturb us unless we disturb it by thinking, `I don't want to hear that sound, it's annoying.' Suffering arises because of this thinking. Right here is the cause of suffering, that we don't know the truth of this matter, we haven't developed the \pali{Buddho}. We are not yet clear, not yet awake, not yet aware. This is the raw, untrained mind. This mind is not yet truly useful to us. \index[general]{mind!developing} Therefore the Buddha taught that this mind must be trained and developed. We must develop the mind just like we develop the body, but we do it in a different way. To develop the body we must exercise it, jogging in the morning and evening and so on. This is exercising the body. As a result the body becomes more agile, stronger, the respiratory and nervous systems become more efficient. To exercise the mind we don't have to move it around, but bring it to a halt, bring it to rest. \index[general]{meditation} For instance, when practising meditation, we take an object, such as the in- and out-breathing, as our foundation. This becomes the focus of our attention and reflection. We look at the breathing. To look at the breathing means to follow the breathing with awareness, noting its rhythm, its coming and going. We put awareness into the breath, following the natural in and out breathing and letting go of all else. As a result of staying on one object of awareness, our mind becomes refreshed. If we let the mind think of this, that and the other, there are many objects of awareness; the mind doesn't unify, it doesn't come to rest. \index[general]{mind!stopping} \index[similes]{using a knife!focusing the mind} To say the mind stops means that it feels as if it's stopped, it doesn't go running here and there. It's like having a sharp knife. If we use the knife to cut at things indiscriminately, such as stones, bricks and grass, our knife will quickly become blunt. We should use it for cutting only the things it was meant for. Our mind is the same. If we let the mind wander after thoughts and feelings which have no value or use, the mind becomes tired and weak. If the mind has no energy, wisdom will not arise, because the mind without energy is the mind without \glsdisp{samadhi}{sam\=adhi.} If the mind hasn't stopped you can't clearly see the sense objects for what they are. The knowledge that the mind is the mind, sense objects are merely sense objects, is the root from which Buddhism has grown and developed. This is the heart of Buddhism. \index[general]{wisdom!arising of} We must cultivate this mind, develop it, training it in calm and insight. We train the mind to have restraint and wisdom by letting the mind stop and allowing wisdom to arise, by knowing the mind as it is. \index[general]{mind!untrained} \index[similes]{little children!untrained mind} You know, the way we human beings are, the way we do things, we are just like little children. A child doesn't know anything. To an adult observing the behaviour of a child, the way it plays and jumps around, its actions don't seem to have much purpose. If our mind is untrained it is like a child. We speak without awareness and act without wisdom. We may fall to ruin or cause untold harm and not even know it. A child is ignorant, it plays as children do. Our ignorant mind is the same. So we should train this mind. The Buddha taught us to train the mind, to teach the mind. Even if we support Buddhism with the four requisites, our support is still superficial, it reaches only the `bark' or `sapwood' of the tree. The real support of Buddhism must be done through the practice, nowhere else, training our actions, speech and thoughts according to the teachings. This is much more fruitful. If we are straight and honest, possessed of restraint and wisdom, our practice will bring prosperity. There will be no cause for spite and hostility. This is how our religion teaches us. \index[general]{precepts} If we determine the precepts simply out of tradition, then even though the Ajahn teaches the truth, our practice will be deficient. We may be able to study the teachings and repeat them, but we have to practise them if we really want to understand. If we do not develop the practice, this may well be an obstacle to our penetrating to the heart of Buddhism for countless lifetimes to come. We will not understand the essence of the Buddhist religion. \index[similes]{using the right key!meditation} Therefore the practice is like a key, the key of meditation. If we have the right key in our hand, no matter how tightly the lock is closed, when we take the key and turn it, the lock falls open. If we have no key we can't open the lock. We will never know what is in the trunk. \index[general]{Truth!speaking the} \index[general]{speech!lying} \index[general]{lying} Actually there are two kinds of knowledge. One who knows the Dhamma doesn't simply speak from memory, he speaks the truth. Worldly people usually speak with conceit. For example, suppose there were two people who hadn't seen each other for a long time, maybe they had gone to live in different provinces or countries for a while, and then one day they happened to meet on the train, `Oh! What a surprise. I was just thinking of looking you up!' Perhaps it's not true. Really they hadn't thought of each other at all, but they say so out of excitement. And so it becomes a lie. Yes, it's lying out of heedlessness. This is lying without knowing it. It's a subtle form of defilement, and it happens very often. So with regard to the mind, Tuccho Pothila followed the instructions of the novice: breathing in, breathing out, mindfully aware of each breath, until he saw the liar within him, the lying of his own mind. He saw the defilements as they came up, just like the lizard coming out of the termite mound. He saw them and perceived their true nature as soon as they arose. He noticed how one minute the mind would concoct one thing, the next moment something else. \index[general]{created phenomena} \index[general]{sa\.nkhata dhammas} \index[general]{asa\.nkhata dhammas} \index[general]{Unconditioned, the} \index[general]{proliferation} Thinking is a \pali{\glsdisp{sankhata-dhamma}{sa\.nkhata dhamma,}} something which is created or concocted from supporting conditions. It's not \pali{asa\.nkhata dhamma}, the unconditioned. The well-trained mind, one with perfect awareness, does not concoct mental states. This kind of mind penetrates to the Noble Truths and transcends any need to depend on externals. To know the Noble Truths is to know the truth. The proliferating mind tries to avoid this truth, saying, `that's good' or `this is beautiful', but if there is \pali{Buddho} in the mind it can no longer deceive us, because we know the mind as it is. The mind can no longer create deluded mental states, because there is the clear awareness that all mental states are unstable, imperfect, and a source of suffering to one who clings to them. \index[general]{mind!the lying mind} For Tuccho Pothila, `the one who knows' was constantly in his mind, wherever he went. He observed the various creations and proliferation of the mind with understanding. He saw how the mind lied in so many ways. He grasped the essence of the practice, seeing that `This lying mind is the one to watch -- this is the one which leads us into extremes of happiness and suffering and causes us to endlessly spin around in the cycle of \glsdisp{samsara}{`sa\d{m}s\=ara',} with its pleasure and pain, good and evil -- all because of this lying mind.' Tuccho Pothila realized the truth, and grasped the essence of the practice, just like a man grasping the tail of the lizard. He saw the workings of the deluded mind. \index[general]{mind!training} For us it's the same. Only this mind is important. That's why we need to train the mind. Now if the mind is the mind, what are we going to train it with? By having continuous sati and \pali{sampaja\~n\~na} we will be able to know the mind. This one who knows is a step beyond the mind, it is that which knows the state of the mind. The mind is the mind. That which knows the mind as simply mind is the one who knows. It is above the mind. The one who knows is above the mind, and that is how it is able to look after the mind, to teach the mind to know what is right and what is wrong. In the end everything comes back to this proliferating mind. If the mind is caught up in its proliferations there is no awareness and the practice is fruitless. \index[general]{Buddho!awareness} \index[general]{Buddho!mantra} \index[general]{Buddho!knowing the mind} \index[general]{Buddho!knowing sense objects} \index[general]{mind!contemplation of} So we must train this mind to hear the Dhamma, to cultivate the \pali{Buddho}, the clear and radiant awareness; that which exists above and beyond the ordinary mind, and knows all that goes on within it. This is why we meditate on the word \pali{Buddho}, so that we can know the mind beyond the mind. Just observe all the mind's movements, whether good or bad, until the one who knows realizes that the mind is simply mind, not a self or a person. This is called \pali{citt\=anupassan\=a}, contemplation of mind.\footnote{One of the four foundations of mindfulness: body, feeling, mind, and dhammas.} Seeing in this way we will understand that the mind is transient, imperfect and ownerless. This mind doesn't belong to us. \index[general]{mindfulness} \index[general]{body!contemplation of} We can summarize thus: the mind is that which acknowledges sense objects; sense objects are sense objects as distinct from the mind; `the one who knows' knows both the mind and the sense objects for what they are. We must use sati to constantly cleanse the mind. Everybody has sati, even a cat has it when it's going to catch a mouse. A dog has it when it barks at people. This is a form of sati, but it's not sati according to the Dhamma. Everybody has sati, but there are different levels of it, just as there are different levels of looking at things. For instance, when I say to contemplate the body, some people say, `What is there to contemplate in the body? Anybody can see it. \pali{Kes\=a} we can see already, \pali{lom\=a} we can see already, hair, nails, teeth and skin we can see already. So what?' \index[general]{sensuality!sensual desire} \index[general]{six senses!craving for} This is how people are. They can see the body all right but their seeing is faulty, they don't see with the \pali{Buddho}, `the one who knows', the awakened one. They only see the body in the ordinary way, they see it visually. Simply to see the body is not enough. If we only see the body there is trouble. You must see the body within the body, then things become much clearer. Just seeing the body you get fooled by it, charmed by its appearance. Not seeing transience, imperfection and ownerlessness, \pali{\glsdisp{kamachanda}{k\=amachanda}} arises. You become fascinated by forms, sounds, odours, flavours and feelings. Seeing in this way is to see with the mundane eye of the flesh, causing you to love and hate and discriminate into pleasant and unpleasant feeling. \index[general]{body!in the body} The Buddha taught that this is not enough. You must see with the `mind's eye'. See the body within the body. If you really look into the body, Ugh! It's so repulsive. There are today's things and yesterday's things all mixed up in there, you can't tell what's what. Seeing in this way is much clearer than to see with the carnal eye. Contemplate, see with the eye of the mind, with the wisdom eye. People understand this in different ways. Some people don't know what there is to contemplate in the five meditations, head hair, body hair, nails, teeth and skin. They say they can see all those things already, but they can only see them with the carnal eye, with this `crazy eye' which only looks at the things it wants to look at. To see the body in the body you have to look more clearly. \index[general]{khandhas!clinging to} This is the practice that can uproot clinging to the five \pali{\glsdisp{khandha}{khandhas.}} To uproot attachment is to uproot suffering, because attachment to the five khandhas is the cause of suffering. If suffering arises it is here. It's not that the five khandhas are in themselves suffering, but the clinging to them as being one's own, that's suffering. \index[similes]{unscrewing a bolt!letting go} If you see the truth of these things clearly through meditation practice, then suffering becomes unwound, like a screw or a bolt. When the bolt is unwound, it withdraws. The mind unwinds in the same way, letting go; withdrawing from the obsession with good and evil, possessions, praise and status, happiness and suffering. \index[general]{disenchantment} If we don't know the truth of these things it's like tightening the screw all the time. It gets tighter and tighter until it's crushing you and you suffer over everything. When you know how things are then you unwind the screw. In Dhamma language we call this the arising of \pali{\glsdisp{nibbida}{nibbid\=a,}} disenchantment. You become weary of things and lay down the fascination with them. If you unwind in this way you will find peace. \index[general]{clinging!suffering of} The cause of suffering is clinging to things. So we should get rid of the cause, cut off its root and not allow it to cause suffering again. People have only one problem -- the problem of clinging. Just because of this one thing people will kill each other. All problems, be they individual, family or social, arise from this one root. Nobody wins, they kill each other but in the end no-one gets anything. It is all pointless, I don't know why people keep on killing each other. \index[general]{dhammas!worldly} \index[general]{eight worldly dhammas} \index[general]{praise and blame} Power, possessions, status, praise, happiness and suffering -- these are the worldly dhammas. These worldly dhammas engulf worldly beings. Worldly beings are led around by the worldly dhammas: gain and loss, acclaim and slander, status and loss of status, happiness and suffering. These dhammas are trouble makers; if you don't reflect on their true nature you will suffer. People even commit murder for the sake of wealth, status or power. Why? Because they take this too seriously. They get appointed to some position and it goes to their heads, like the man who became headman of the village. After his appointment he became `power-drunk'. If any of his old friends came to see him he'd say, `Don't come around so often. Things aren't the same anymore.' The Buddha taught us to understand the nature of possessions, status, praise and happiness. Take these things as they come but let them be. Don't let them go to your head. If you don't really understand these things, you become fooled by your power, your children and relatives, by everything! If you understand them clearly, you know they're all impermanent conditions. If you cling to them, they become defiled. \index[general]{conventions!of names} \index[general]{names} All of these things arise afterwards. When people are first born there are simply \pali{\glsdisp{nama}{n\=ama}} and \pali{\glsdisp{rupa}{r\=upa,}} that's all. We add on the business of `Mr. Jones', `Miss Smith' or whatever later on. This is done according to convention. Still later there are the appendages of `Colonel', `General' and so on. If we don't really understand these things we think they are real and carry them around with us. We carry possessions, status, name and rank around. If you have power you can call all the tunes \ldots{} `Take this one and execute him. Take that one and throw him in jail.' Rank gives power. Clinging takes hold here at this word, `rank'. As soon as people have rank they start giving orders; right or wrong, they just act on their moods. So they go on making the same old mistakes, deviating further and further from the true path. \index[general]{identity} One who understands the Dhamma won't behave like this. Good and evil have been in the world since who knows when. If possessions and status come your way, then let them simply be possessions and status -- don't let them become your identity. Just use them to fulfil your obligations and leave it at that. You remain unchanged. If we have meditated on these things, no matter what comes our way we will not be mislead by it. We will be untroubled, unaffected and constant. Everything is pretty much the same, after all. This is how the Buddha wanted us to understand things. No matter what you receive, the mind does not add anything to it. They appoint you a city councillor, `Okay, so I'm a city councillor, but I'm not.' They appoint you head of the group, `Sure I am, but I'm not.' Whatever they make of you, `Yes I am, but I'm not!' In the end what are we anyway? We all just die in the end. No matter what they make you, in the end it's all the same. What can you say? If you can see things in this way you will have a solid abiding and true contentment. Nothing is changed. Don't be fooled by things. Whatever comes your way, it's just conditions. There's nothing which can entice a mind like this to create or proliferate, to seduce it into greed, aversion or delusion. \index[general]{morality!as a support for Buddhism} \index[general]{supporting!through morality} \index[similes]{three parts of a tree!s\={\i}la, sam\=adhi, pa\~n\~n\=a} This is what it is to be a true supporter of Buddhism. Whether you are among those who are being supported (i.e., the Sa\.ngha) or those who are supporting (the laity) please consider this thoroughly. Cultivate the \pali{\glsdisp{sila-dhamma}{s\={\i}la-dhamma}} within you. This is the surest way to support Buddhism. To support Buddhism with the offerings of food, shelter and medicine is good also, but such offerings only reach the `sapwood' of Buddhism. Please don't forget this. A tree has bark, sapwood and heartwood, and these three parts are interdependent. The heartwood must rely on the bark and the sapwood. The sapwood relies on the bark and the heartwood. They all exist interdependently, just like the teachings of moral discipline, concentration and wisdom.\footnote{S\={\i}la, sam\=adhi, pa\~n\~n\=a.} The teaching on moral discipline is to establish your speech and actions in rectitude. The teaching on concentration is to firmly fix the mind. The teaching on wisdom is the thorough understanding of the nature of all conditions. Study this, practise this, and you will understand Buddhism in the most profound way. If you don't realize these things, you will be fooled by possessions, fooled by rank, fooled by anything you come into contact with. Simply supporting Buddhism in the external way will never put an end to the fighting and squabbling, the grudges and animosity, the stabbing and shooting. If these things are to cease we must reflect on the nature of possessions, rank, praise, happiness and suffering. We must consider our lives and bring them in line with the teaching. We should reflect that all beings in the world are part of one whole. We are like them, they are like us. They have happiness and suffering just like we do. It's all much the same. If we reflect in this way, peace and understanding will arise. This is the foundation of Buddhism.
\documentclass[12pt, a4paper]{article} \usepackage[utf8]{inputenc} \usepackage{hyperref} \usepackage[left=1.00in, right=1.00in, top=1.00in, bottom=1.00in]{geometry} \usepackage{graphicx} \usepackage{xcolor} \graphicspath{ {./} } \title{CS348 Project - Final Report} \author{Abdullah Bin Assad\and Chandana Sathish \and Lukman Mohamed \and Vikram Subramanian \and Dhvani Patel \\} \begin{document} \maketitle \begin{center} \url{https://watch-dog.azurewebsites.net/} \end{center} \section*{Application description} \subsection*{Application User} We have created an interactive web app for people interested in exploring crime data in the Greater Toronto Area. People who wish to assess how safe a neighbourhood is before investing in a new property or novice drivers trying to avoid accident-prone roads or just people curious about crime rates around them can greatly benefit from our application. \subsection*{Interaction with the app} A user would simply search for a query (as seen on the demo application) using the drop-down on certain words in the question to tailor the search to their needs. For example, “I want to explore bicycle theft crimes in 2019 (year) citywide on a bar chart” can be one of the many queries a user selects. Alternatively, a user can also pick from a list of predefined queries if they are unsure about where to start. Once the user clicks “OK”, the page updates to display the requested query and allows them to change the representation/visualization of the data as well as further refine their search with more options. We also plan on adding additional features as follows. \subsection*{Key features} \begin{enumerate} \item Filter crime/traffic events (starter question with drop-down for filtering different columns as seen in demo) and show results on a table \begin{itemize} \item Filter by crime indicator \item Filter by year/month \item Filter by neighbourhood \end{itemize} \item Display crime data \begin{itemize} \item bar chart, line chart, and pie chart \item map, heat map \item summary/total count \end{itemize} \item Create predefined complex queries in the form of question and answer \begin{itemize} \item Example - At what hour do most crimes occur, which neighbourhood has the most number of traffic accidents, is there a correlation between education/demographic and crime, etc. \end{itemize} \item Provide users with information on which police division they are situated closest to based on the address they provide us with \item Report a crime \item Interactive “How well do you know your city” feature \begin{itemize} \item Let the user guess certain values from a query they select, then show them the actual results and tell them how close they were \end{itemize} \end{enumerate} \subsection*{Data} The tables we get from the Toronto Police Open Data: \begin{itemize} \item \url{https://data.torontopolice.on.ca/pages/open-data} \end{itemize} We get a few additional columns of the census from the Toronto City Open Data: \begin{itemize} \item \url{https://open.toronto.ca/dataset/neighbourhood-profiles/} \end{itemize} \color{black} The tables themselves are a little difficult to work with. Therefore, we create a data parser (in code.zip) to convert it to .csv files that fulfill our requirements. Sample data and production data are part of the code.zip as csv files (ex. Neighbourhood.csv, CrimeEvent.csv). \subsection*{System support} \hspace{\parindent}Our interface consists of an interactive web-app. Both the web application and the SQL database are hosted on Microsoft Azure. Azure AppServices and MySQL are modern, scalable, efficient and flexible. This setup is ideal and efficient for building a web app such as ours; plus Azure is cheaper than the alternatives. The back end is made up Node.js + Express.js from which API end points are exposed. This is what directly talks with the database. The front end is a React application. \color{blue}The notalable NPM packages used include: the Semantic UI React library for UI components, the Mapbox API for the maps you see in the application, ChartJS and D3.js for the data presentation, and ag-grid for the table.\color{black} Thus, our web application code mostly consists of JavaScript. Members of our group have experience with Node.js and React which gave us an excellent basis for our project. \section*{Design database schema} \subsection*{List of assumptions} \begin{itemize} \item all reported times of incidents are either in or after 2014 \item for regular crimes and traffic accidents, the time and place of the incident are recorded accurately and not left out (not NULL mostly) \item the level and standard of reporting crimes is consistent in all neighbourhoods (required for useful analysis and comparison among neighbourhoods) \item the cause of the traffic accident is taken from testimonies of all parties involved and is not one sided (although hard to avoid survivorship bias) \item the police arrive at the scene of an accident within reasonable time to be able to assess the road conditions leading up to the cause of the accident \item all parties involved in an accident are accounted for (driver, passengers, pedestrians) \item the status of stolen bikes is updated as best as possible (most bikes are never recovered) \end{itemize} \subsection*{E/R diagram} \color{black} \includegraphics[scale=0.3]{ER Diagram.png} Note: Check the standalone image of the ER diagram if this one is too small. \subsection*{Relational Data Model} \begin{itemize} \item IncidentTime \begin{itemize} \item \underline{time\_id} : INT \item hour : INT \item day : INT \item month : INT \item year : INT \item day\_of\_week : INT \end{itemize} \item PoliceDivision \begin{itemize} \item \underline{division} : INT \item address : VARCHAR(50) \item area : DECIMAL(12, 9) \item shapeLeng : DECIMAL(12, 6) \item shapeArea : DECIMAL(11, 3) \end{itemize} \item Neighbourhood \begin{itemize} \item \underline{hood\_id} : INT \item name : VARCHAR(50) \item employment\_rate : DECIMAL(4, 2) \item high\_school : DECIMAL(4, 2) \item university : DECIMAL(4, 2) \item technical\_degree : DECIMAL(4, 2) \item division : INT (Foreign Key Referencing PoliceDivision(division)) \end{itemize} \item BikeTheft \begin{itemize} \item \underline{event\_id} : INT (Foreign Key Referencing CrimeEvent(event\_id)) \item colour : VARCHAR(50) \item make : VARCHAR(50) \item model : VARCHAR(50) \item speed : VARCHAR(50) \item bike\_type : VARCHAR(50) \item status : VARCHAR(50) \item cost : DECIMAL(8, 2) \end{itemize} \item RegularCrime \begin{itemize} \item \underline{crime\_id} : INT \item offence : VARCHAR(50) \item MCI : VARCHAR(50) \end{itemize} \item CrimeEvent \begin{itemize} \item \underline{event\_id} : INT \item occurrence\_time\_id : INT (Foreign Key Referencing IncidentTime(time\_id)) \item reported\_time\_id : INT (Foreign Key Referencing IncidentTime(time\_id)) \item crime\_id : INT (Foreign Key Referencing RegularCrime(crime\_id)) \item hood\_id : INT (Foreign Key Referencing Neighbourhood(hood\_id)) \item latitude : DECIMAL(10,8) \item longitude : DECIMAL(11,8) \item premise\_type : VARCHAR(50) \end{itemize} \item InvolvedPerson \begin{itemize} \item \underline{accident\_id} : INT (Foreign Key Referencing TrafficEvent(accident\_id)) \item \underline{person\_id} : INT \item involvement\_type : VARCHAR(50) \item age : INT \item injury : VARCHAR(50) \item vehicle\_type : VARCHAR(50) \item action\_taken : VARCHAR(50) \end{itemize} \item RoadCondition \begin{itemize} \item \underline{road\_condition\_id} : INT \item classification : VARCHAR(50) \item traffic\_control\_type : VARCHAR(50) \item visibility : VARCHAR(50) \item surface\_condition : VARCHAR(50) \end{itemize} \item TrafficEvent \begin{itemize} \item \underline{accident\_id} : INT \item occurrence\_time\_id : INT (Foreign Key Referencing IncidentTime(time\_id)) \item road\_condition\_id : INT (Foreign Key Referencing RoadCondition(road\_condition\_id)) \item hood\_id : INT (Foreign Key Referencing Neighbourhood(hood\_id)) \item latitude : DECIMAL(10,8) \item longitude : DECIMAL(11,8) \end{itemize} \end{itemize} \color{blue} \subsection*{Application Overview} \color{black} \begin{itemize} \item Starter Question \begin{itemize} \item Located at very top of the application . \item It filters the information in the cards below by crime type (regular crimes, bike thefts and traffic accidents). \item For crimes we have filters for the major crime indicator (MCI), date (year or month) and location (citywide, neighbourhood and police division). \item By default, it is set to show all crimes citywide (Toronto) that happened in 2019. \item Click OK and the userr new search will update the cards below. \end{itemize} \item Data Cards \begin{itemize} \item All queries have similar cards with different data. \item Table Card \begin{itemize} \item Located right below the Starter Question. \item Contains the raw data from the query. \item Paginated and filterable. \end{itemize} \item Heat-map Card \begin{itemize} \item Located right below the Table Card. \item Shows the amount of crimes per time period. \item Interact to refine the time range. \end{itemize} \item Summary Card \begin{itemize} \item Shows the number of crimes per major crime indicator. \end{itemize} \item Cluster Map Card \begin{itemize} \item Shows each individual crime location. \item We can zoom in on the cluster to break it up and see individual locations. \end{itemize} \item Line Chart Card \begin{itemize} \item Shows the number of crimes per month if our date type is set to year, or day if our date type is set to month. \end{itemize} \item There are a few other data cards besides the ones mentioned above: horizontal bar char, a doughnut chart, and a pie chart. \item Note that, since it may be hard to view certain small numbers, the user can click on a chart label to remove it. \item Bike Thefts and Traffic Incidents \begin{itemize} \item Have the same cards. \item As different types of data are collected for different types of crimes, different types of data are mentioned in the above data cards. \end{itemize} \end{itemize} \item Police Division Map \begin{itemize} \item Located below everything mentioned above. \item Shows the amount of crimes per police division and where the police divisions are located. \item Provide an address and the application will output the closest police division. \end{itemize} \item Additional Filters \begin{itemize} \item A few filters are used in the application. \item For example, we can look at the robberies that happened in rexdale-kiplin in March 2018. \item We can also filter by a police division instead. \end{itemize} \item Report Crime \begin{itemize} \item Located at the bottom right of the application. \item Fill this out to report a crime and update the database. \item Please recall that the userr new crime will be added to 2020 (so update the filter before checking!). \end{itemize} \item Batman Mode \begin{itemize} \item The button to activate it is located at the top right of the application. \item A game that tests how well the user know the city of Toronto and its crime. \item Once activated, the user has to guess the total number of crimes that occurred and the crimes per month/day for the selected query. \item Then at the end, users can see their score for guessing both the data. \item This is a fun way for users to explore the data and challenge their friends. \end{itemize} \item Predefined Queries \begin{itemize} \item Located at the same spot as the Starter Question. \item An alternative to the Starter Question if the user is not sure what they are looking for. \item Select the toggle to the left of the Starter Sentence to switch to Predefined Queries. \item Currently we have 21 queries, but more can be added quite easily. \end{itemize} \end{itemize} \color{blue} \subsection*{Changes/Improvements Since Milestone 2} \color{black} \begin{itemize} \item Created additional indices to speed up queries for the predefined questions feature (2.4 seconds to 0.6 seconds!): \begin{itemize} \item CREATE INDEX MCI ON RegularCrime(MCI); \item CREATE INDEX BikeType ON BikeTheft(bike\_type); \item CREATE INDEX InvolvedPersonType ON InvolvedPerson(involvement\_type); \end{itemize} \item Implemented all remaining features and polished application \end{itemize} \end{document}
\documentclass[12pt,landscape]{article} %\usepackage{lmodern} \usepackage{amssymb,amsmath} \usepackage{bm} \usepackage{graphicx} \usepackage{microtype} \usepackage{hyperref} \pagestyle{empty} \usepackage{titlesec} \titleformat*{\section}{\LARGE\bfseries} \titleformat*{\subsection}{\LARGE\bfseries} \titleformat*{\subsubsection}{\LARGE\bfseries} \setlength{\parindent}{0pt} \setlength{\parskip}{1.2ex} \setlength{\parindent}{0pt} \setlength{\parskip}{1.2ex} \setlength{\oddsidemargin}{-16mm} \setlength{\textwidth}{260mm} \setlength{\columnsep}{0.5in} \setlength{\columnseprule}{1pt} \setlength{\textheight}{202mm} \setlength{\topmargin}{-32mm} \setlength{\headsep}{0.25in} \hypersetup { pdfauthor = { Marco Fasondini }, pdftitle={ foo }, colorlinks=TRUE, linkcolor=black, citecolor=blue, urlcolor=blue } \usepackage{upquote} \usepackage{listings} \usepackage{xcolor} \lstset{ basicstyle=\ttfamily\footnotesize, upquote=true, breaklines=true, breakindent=0pt, keepspaces=true, showspaces=false, columns=fullflexible, showtabs=false, showstringspaces=false, escapeinside={(*@}{@*)}, extendedchars=true, } \newcommand{\HLJLt}[1]{#1} \newcommand{\HLJLw}[1]{#1} \newcommand{\HLJLe}[1]{#1} \newcommand{\HLJLeB}[1]{#1} \newcommand{\HLJLo}[1]{#1} \newcommand{\HLJLk}[1]{\textcolor[RGB]{148,91,176}{\textbf{#1}}} \newcommand{\HLJLkc}[1]{\textcolor[RGB]{59,151,46}{\textit{#1}}} \newcommand{\HLJLkd}[1]{\textcolor[RGB]{214,102,97}{\textit{#1}}} \newcommand{\HLJLkn}[1]{\textcolor[RGB]{148,91,176}{\textbf{#1}}} \newcommand{\HLJLkp}[1]{\textcolor[RGB]{148,91,176}{\textbf{#1}}} \newcommand{\HLJLkr}[1]{\textcolor[RGB]{148,91,176}{\textbf{#1}}} \newcommand{\HLJLkt}[1]{\textcolor[RGB]{148,91,176}{\textbf{#1}}} \newcommand{\HLJLn}[1]{#1} \newcommand{\HLJLna}[1]{#1} \newcommand{\HLJLnb}[1]{#1} \newcommand{\HLJLnbp}[1]{#1} \newcommand{\HLJLnc}[1]{#1} \newcommand{\HLJLncB}[1]{#1} \newcommand{\HLJLnd}[1]{\textcolor[RGB]{214,102,97}{#1}} \newcommand{\HLJLne}[1]{#1} \newcommand{\HLJLneB}[1]{#1} \newcommand{\HLJLnf}[1]{\textcolor[RGB]{66,102,213}{#1}} \newcommand{\HLJLnfm}[1]{\textcolor[RGB]{66,102,213}{#1}} \newcommand{\HLJLnp}[1]{#1} \newcommand{\HLJLnl}[1]{#1} \newcommand{\HLJLnn}[1]{#1} \newcommand{\HLJLno}[1]{#1} \newcommand{\HLJLnt}[1]{#1} \newcommand{\HLJLnv}[1]{#1} \newcommand{\HLJLnvc}[1]{#1} \newcommand{\HLJLnvg}[1]{#1} \newcommand{\HLJLnvi}[1]{#1} \newcommand{\HLJLnvm}[1]{#1} \newcommand{\HLJLl}[1]{#1} \newcommand{\HLJLld}[1]{\textcolor[RGB]{148,91,176}{\textit{#1}}} \newcommand{\HLJLs}[1]{\textcolor[RGB]{201,61,57}{#1}} \newcommand{\HLJLsa}[1]{\textcolor[RGB]{201,61,57}{#1}} \newcommand{\HLJLsb}[1]{\textcolor[RGB]{201,61,57}{#1}} \newcommand{\HLJLsc}[1]{\textcolor[RGB]{201,61,57}{#1}} \newcommand{\HLJLsd}[1]{\textcolor[RGB]{201,61,57}{#1}} \newcommand{\HLJLsdB}[1]{\textcolor[RGB]{201,61,57}{#1}} \newcommand{\HLJLsdC}[1]{\textcolor[RGB]{201,61,57}{#1}} \newcommand{\HLJLse}[1]{\textcolor[RGB]{59,151,46}{#1}} \newcommand{\HLJLsh}[1]{\textcolor[RGB]{201,61,57}{#1}} \newcommand{\HLJLsi}[1]{#1} \newcommand{\HLJLso}[1]{\textcolor[RGB]{201,61,57}{#1}} \newcommand{\HLJLsr}[1]{\textcolor[RGB]{201,61,57}{#1}} \newcommand{\HLJLss}[1]{\textcolor[RGB]{201,61,57}{#1}} \newcommand{\HLJLssB}[1]{\textcolor[RGB]{201,61,57}{#1}} \newcommand{\HLJLnB}[1]{\textcolor[RGB]{59,151,46}{#1}} \newcommand{\HLJLnbB}[1]{\textcolor[RGB]{59,151,46}{#1}} \newcommand{\HLJLnfB}[1]{\textcolor[RGB]{59,151,46}{#1}} \newcommand{\HLJLnh}[1]{\textcolor[RGB]{59,151,46}{#1}} \newcommand{\HLJLni}[1]{\textcolor[RGB]{59,151,46}{#1}} \newcommand{\HLJLnil}[1]{\textcolor[RGB]{59,151,46}{#1}} \newcommand{\HLJLnoB}[1]{\textcolor[RGB]{59,151,46}{#1}} \newcommand{\HLJLoB}[1]{\textcolor[RGB]{102,102,102}{\textbf{#1}}} \newcommand{\HLJLow}[1]{\textcolor[RGB]{102,102,102}{\textbf{#1}}} \newcommand{\HLJLp}[1]{#1} \newcommand{\HLJLc}[1]{\textcolor[RGB]{153,153,119}{\textit{#1}}} \newcommand{\HLJLch}[1]{\textcolor[RGB]{153,153,119}{\textit{#1}}} \newcommand{\HLJLcm}[1]{\textcolor[RGB]{153,153,119}{\textit{#1}}} \newcommand{\HLJLcp}[1]{\textcolor[RGB]{153,153,119}{\textit{#1}}} \newcommand{\HLJLcpB}[1]{\textcolor[RGB]{153,153,119}{\textit{#1}}} \newcommand{\HLJLcs}[1]{\textcolor[RGB]{153,153,119}{\textit{#1}}} \newcommand{\HLJLcsB}[1]{\textcolor[RGB]{153,153,119}{\textit{#1}}} \newcommand{\HLJLg}[1]{#1} \newcommand{\HLJLgd}[1]{#1} \newcommand{\HLJLge}[1]{#1} \newcommand{\HLJLgeB}[1]{#1} \newcommand{\HLJLgh}[1]{#1} \newcommand{\HLJLgi}[1]{#1} \newcommand{\HLJLgo}[1]{#1} \newcommand{\HLJLgp}[1]{#1} \newcommand{\HLJLgs}[1]{#1} \newcommand{\HLJLgsB}[1]{#1} \newcommand{\HLJLgt}[1]{#1} \def\qqand{\qquad\hbox{and}\qquad} \def\qqfor{\qquad\hbox{for}\qquad} \def\qqas{\qquad\hbox{as}\qquad} \def\half{ {1 \over 2} } \def\D{ {\rm d} } \def\I{ {\rm i} } \def\E{ {\rm e} } \def\C{ {\mathbb C} } \def\R{ {\mathbb R} } \def\H{ {\mathbb H} } \def\Z{ {\mathbb Z} } \def\CC{ {\cal C} } \def\FF{ {\cal F} } \def\HH{ {\cal H} } \def\LL{ {\cal L} } \def\vc#1{ {\mathbf #1} } \def\bbC{ {\mathbb C} } \def\fR{ f_{\rm R} } \def\fL{ f_{\rm L} } \def\qqqquad{\qquad\qquad} \def\qqwhere{\qquad\hbox{where}\qquad} \def\Res_#1{\underset{#1}{\rm Res}\,} \def\sech{ {\rm sech}\, } \def\acos{ {\rm acos}\, } \def\asin{ {\rm asin}\, } \def\atan{ {\rm atan}\, } \def\Ei{ {\rm Ei}\, } \def\upepsilon{\varepsilon} \def\Xint#1{ \mathchoice {\XXint\displaystyle\textstyle{#1} }% {\XXint\textstyle\scriptstyle{#1} }% {\XXint\scriptstyle\scriptscriptstyle{#1} }% {\XXint\scriptscriptstyle\scriptscriptstyle{#1} }% \!\int} \def\XXint#1#2#3{ {\setbox0=\hbox{$#1{#2#3}{\int}$} \vcenter{\hbox{$#2#3$}}\kern-.5\wd0} } \def\ddashint{\Xint=} \def\dashint{\Xint-} % \def\dashint \def\infdashint{\dashint_{-\infty}^\infty} \def\addtab#1={#1\;&=} \def\ccr{\\\addtab} \def\ip<#1>{\left\langle{#1}\right\rangle} \def\dx{\D x} \def\dt{\D t} \def\dz{\D z} \def\ds{\D s} \def\rR{ {\rm R} } \def\rL{ {\rm L} } \def\norm#1{\left\| #1 \right\|} \def\pr(#1){\left({#1}\right)} \def\br[#1]{\left[{#1}\right]} \def\abs#1{\left|{#1}\right|} \def\fpr(#1){\!\pr({#1})} \def\sopmatrix#1{ \begin{pmatrix}#1\end{pmatrix} } \def\endash{–} \def\emdash{—} \def\mdblksquare{\blacksquare} \def\lgblksquare{\blacksquare} \def\scre{\E} \def\mapengine#1,#2.{\mapfunction{#1}\ifx\void#2\else\mapengine #2.\fi } \def\map[#1]{\mapengine #1,\void.} \def\mapenginesep_#1#2,#3.{\mapfunction{#2}\ifx\void#3\else#1\mapengine #3.\fi } \def\mapsep_#1[#2]{\mapenginesep_{#1}#2,\void.} \def\vcbr[#1]{\pr(#1)} \def\bvect[#1,#2]{ { \def\dots{\cdots} \def\mapfunction##1{\ | \ ##1} \sopmatrix{ \,#1\map[#2]\, } } } \def\vect[#1]{ {\def\dots{\ldots} \vcbr[{#1}] } } \def\vectt[#1]{ {\def\dots{\ldots} \vect[{#1}]^{\top} } } \def\Vectt[#1]{ { \def\mapfunction##1{##1 \cr} \def\dots{\vdots} \begin{pmatrix} \map[#1] \end{pmatrix} } } \def\addtab#1={#1\;&=} \def\ccr{\\\addtab} \def\questionequals{= \!\!\!\!\!\!{\scriptstyle ? \atop }\,\,\,} \def\cent#1{\begin{center}#1\end{center} } \lstset{ basicstyle=\ttfamily, } \begin{document} {\LARGE \sf \textbf{Applied Complex Analysis (2021)} \section{Solution Sheet 3} \subsection{Problem 1.1} \subsubsection{1.} Take as an initial guess \[ \phi_1(z) = {\sqrt{z-1} \sqrt{z+1} \over 2\I(1 + z^2)} \] This satisfies for $-1 < x < 1$ \[ \phi_1^+(x) -\phi_1^-(x) = { \sqrt{1-x^2} \over 2(1 + x^2)} - {- \sqrt{1-x^2} \over 2(1 + x^2)} = {\sqrt{1 - x^2} \over 1+x^2} \] Further, as $z \rightarrow \infty$, \[ \phi_1(z) \sim {z \over \I(1+ z^2)} \rightarrow 0 \] The catch is that it has poles at $\pm \I$: \begin{align*} \phi_1(z) = -{\sqrt{\I -1} \sqrt{\I+1} \over 4} { 1 \over z - \I} + O(1) \\ \phi_1(z) = {\sqrt{-\I -1} \sqrt{-\I+1} \over 4} { 1 \over z + \I} + O(1) \end{align*} Thus it follows that \[ \phi(z) = \phi_1(z) + {\sqrt{\I -1} \sqrt{\I+1} \over 4} { 1 \over z - \I} - {\sqrt{-\I -1} \sqrt{-\I+1} \over 4} { 1 \over z + \I} \] is \begin{itemize} \item[1. ] Analyticity: Analytic at $\pm \I$ and off $[-1,1]$ \item[2. ] Decay: $\phi(\infty) = 0$ \item[3. ] Regularity: Has weaker than pole singularities \item[4. ] Jump: Satisfies \end{itemize} \[ \phi_+(x) - \phi_-(x) = {\sqrt{1-x^2} \over 1+x^2} \] By Plemelj II, this must be the Cauchy transform. \emph{Demonstration} We will see experimentally that it correct. First we do a phase plot to make sure we satisfy (Analyticity): \begin{lstlisting} (*@\HLJLk{using}@*) (*@\HLJLn{ComplexPhasePortrait}@*)(*@\HLJLp{,}@*) (*@\HLJLn{Plots}@*)(*@\HLJLp{,}@*) (*@\HLJLn{ApproxFun}@*)(*@\HLJLp{,}@*) (*@\HLJLn{SingularIntegralEquations}@*) (*@\HLJLnf{H}@*)(*@\HLJLp{(}@*)(*@\HLJLn{f}@*)(*@\HLJLp{)}@*) (*@\HLJLoB{=}@*) (*@\HLJLoB{-}@*)(*@\HLJLnf{hilbert}@*)(*@\HLJLp{(}@*)(*@\HLJLn{f}@*)(*@\HLJLp{)}@*) (*@\HLJLnf{H}@*)(*@\HLJLp{(}@*)(*@\HLJLn{f}@*)(*@\HLJLp{,}@*)(*@\HLJLn{x}@*)(*@\HLJLp{)}@*) (*@\HLJLoB{=}@*) (*@\HLJLoB{-}@*)(*@\HLJLnf{hilbert}@*)(*@\HLJLp{(}@*)(*@\HLJLn{f}@*)(*@\HLJLp{,}@*)(*@\HLJLn{x}@*)(*@\HLJLp{)}@*) (*@\HLJLn{\ensuremath{\varphi}}@*) (*@\HLJLoB{=}@*) (*@\HLJLn{z}@*) (*@\HLJLoB{->}@*) (*@\HLJLnf{sqrt}@*)(*@\HLJLp{(}@*)(*@\HLJLn{z}@*)(*@\HLJLoB{-}@*)(*@\HLJLni{1}@*)(*@\HLJLp{)}@*)(*@\HLJLnf{sqrt}@*)(*@\HLJLp{(}@*)(*@\HLJLn{z}@*)(*@\HLJLoB{+}@*)(*@\HLJLni{1}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{/}@*)(*@\HLJLp{(}@*)(*@\HLJLni{2}@*)(*@\HLJLn{im}@*)(*@\HLJLoB{*}@*)(*@\HLJLp{(}@*)(*@\HLJLni{1}@*)(*@\HLJLoB{+}@*)(*@\HLJLn{z}@*)(*@\HLJLoB{{\textasciicircum}}@*)(*@\HLJLni{2}@*)(*@\HLJLp{))}@*) (*@\HLJLoB{+}@*) (*@\HLJLnf{sqrt}@*)(*@\HLJLp{(}@*)(*@\HLJLn{im}@*)(*@\HLJLoB{-}@*)(*@\HLJLni{1}@*)(*@\HLJLp{)}@*)(*@\HLJLnf{sqrt}@*)(*@\HLJLp{(}@*)(*@\HLJLn{im}@*)(*@\HLJLoB{+}@*)(*@\HLJLni{1}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{/}@*)(*@\HLJLni{4}@*)(*@\HLJLoB{*}@*)(*@\HLJLni{1}@*)(*@\HLJLoB{/}@*)(*@\HLJLp{(}@*)(*@\HLJLn{z}@*)(*@\HLJLoB{-}@*)(*@\HLJLn{im}@*)(*@\HLJLp{)}@*) (*@\HLJLoB{-}@*) (*@\HLJLnf{sqrt}@*)(*@\HLJLp{(}@*)(*@\HLJLoB{-}@*)(*@\HLJLn{im}@*)(*@\HLJLoB{-}@*)(*@\HLJLni{1}@*)(*@\HLJLp{)}@*)(*@\HLJLnf{sqrt}@*)(*@\HLJLp{(}@*)(*@\HLJLoB{-}@*)(*@\HLJLn{im}@*)(*@\HLJLoB{+}@*)(*@\HLJLni{1}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{/}@*)(*@\HLJLni{4}@*)(*@\HLJLoB{*}@*)(*@\HLJLni{1}@*)(*@\HLJLoB{/}@*)(*@\HLJLp{(}@*)(*@\HLJLn{z}@*)(*@\HLJLoB{+}@*)(*@\HLJLn{im}@*)(*@\HLJLp{)}@*) (*@\HLJLnf{phaseplot}@*)(*@\HLJLp{(}@*)(*@\HLJLoB{-}@*)(*@\HLJLnfB{3..3}@*)(*@\HLJLp{,}@*) (*@\HLJLoB{-}@*)(*@\HLJLnfB{3..3}@*)(*@\HLJLp{,}@*) (*@\HLJLn{\ensuremath{\varphi}}@*)(*@\HLJLp{)}@*) \end{lstlisting} \includegraphics[width=\linewidth]{C:/Users/mfaso/OneDrive/Documents/GitHub/M3M6AppliedComplexAnalysis/output/figures/Solutions3_1_1.pdf} We can also see from the phase plot (Regularity): we have weaker than pole singularities, otherwise we would have at least a full,counter clockwise colour wheel. We can check decay as well: \begin{lstlisting} (*@\HLJLnf{\ensuremath{\varphi}}@*)(*@\HLJLp{(}@*)(*@\HLJLnfB{200.0}@*)(*@\HLJLoB{+}@*)(*@\HLJLnfB{200.0}@*)(*@\HLJLn{im}@*)(*@\HLJLp{)}@*) \end{lstlisting} \begin{lstlisting} 0.0005177682933717976 + 0.000517765612545622im \end{lstlisting} Finally, we compare it numerically it to \texttt{cauchy(f, z)} which is implemented in SingularIntegralEquations.jl: \begin{lstlisting} (*@\HLJLn{x}@*) (*@\HLJLoB{=}@*) (*@\HLJLnf{Fun}@*)(*@\HLJLp{()}@*) (*@\HLJLnf{\ensuremath{\varphi}}@*)(*@\HLJLp{(}@*)(*@\HLJLnfB{2.0}@*)(*@\HLJLoB{+}@*)(*@\HLJLnfB{2.0}@*)(*@\HLJLn{im}@*)(*@\HLJLp{),}@*)(*@\HLJLnf{cauchy}@*)(*@\HLJLp{(}@*)(*@\HLJLnf{sqrt}@*)(*@\HLJLp{(}@*)(*@\HLJLni{1}@*)(*@\HLJLoB{-}@*)(*@\HLJLn{x}@*)(*@\HLJLoB{{\textasciicircum}}@*)(*@\HLJLni{2}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{/}@*)(*@\HLJLp{(}@*)(*@\HLJLni{1}@*)(*@\HLJLoB{+}@*)(*@\HLJLn{x}@*)(*@\HLJLoB{{\textasciicircum}}@*)(*@\HLJLni{2}@*)(*@\HLJLp{),}@*) (*@\HLJLnfB{2.0}@*)(*@\HLJLoB{+}@*)(*@\HLJLnfB{2.0}@*)(*@\HLJLn{im}@*)(*@\HLJLp{)}@*) \end{lstlisting} \begin{lstlisting} (0.05303535516221752 + 0.05036581190871381im, 0.05303535516221748 + 0.05036 581190871378im) \end{lstlisting} \subsubsection{2.} Recall that \[ \psi(z) = {\log(z-1) - \log(z+1) \over 2 \pi \I} \] satisfies \[ \psi_+(x) - \psi_-(x) = 1 \] Therefore, consider \[ \phi_1(z) = {\psi(z) \over 2 + z} \] This has the right jump, but has an extra pole at $z = -2$: for $x < -1$ we have \[ \phi_1(x) = {\log_+(x-1) - \log_+(x+1) \over 2 \pi \I} {1 \over 2 + x} = {\log(1-x) - \log(-1-x) \over 2 \pi \I} {1 \over 2 + x} \] hence we arrive at the solution \[ \phi_1(z) - {\log 3 \over 2 \pi \I (2+z)} \] We can verify that $\phi_1(\infty) = 0$. \begin{lstlisting} (*@\HLJLn{\ensuremath{\varphi}}@*) (*@\HLJLoB{=}@*) (*@\HLJLn{z}@*) (*@\HLJLoB{->}@*) (*@\HLJLp{(}@*)(*@\HLJLnf{log}@*)(*@\HLJLp{(}@*)(*@\HLJLn{z}@*)(*@\HLJLoB{-}@*)(*@\HLJLni{1}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{-}@*)(*@\HLJLnf{log}@*)(*@\HLJLp{(}@*)(*@\HLJLn{z}@*)(*@\HLJLoB{+}@*)(*@\HLJLni{1}@*)(*@\HLJLp{))}@*) (*@\HLJLoB{/}@*) (*@\HLJLp{((}@*)(*@\HLJLni{2}@*)(*@\HLJLn{\ensuremath{\pi}}@*)(*@\HLJLoB{*}@*)(*@\HLJLn{im}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{*}@*)(*@\HLJLp{(}@*)(*@\HLJLni{2}@*)(*@\HLJLoB{+}@*)(*@\HLJLn{z}@*)(*@\HLJLp{))}@*) (*@\HLJLoB{-}@*) (*@\HLJLnf{log}@*)(*@\HLJLp{(}@*)(*@\HLJLni{3}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{/}@*)(*@\HLJLp{(}@*)(*@\HLJLni{2}@*)(*@\HLJLn{\ensuremath{\pi}}@*)(*@\HLJLoB{*}@*)(*@\HLJLn{im}@*)(*@\HLJLoB{*}@*)(*@\HLJLp{(}@*)(*@\HLJLni{2}@*)(*@\HLJLoB{+}@*)(*@\HLJLn{z}@*)(*@\HLJLp{))}@*) (*@\HLJLnf{phaseplot}@*)(*@\HLJLp{(}@*)(*@\HLJLoB{-}@*)(*@\HLJLnfB{3..3}@*)(*@\HLJLp{,}@*) (*@\HLJLoB{-}@*)(*@\HLJLnfB{3..3}@*)(*@\HLJLp{,}@*) (*@\HLJLn{\ensuremath{\varphi}}@*)(*@\HLJLp{)}@*) \end{lstlisting} \includegraphics[width=\linewidth]{C:/Users/mfaso/OneDrive/Documents/GitHub/M3M6AppliedComplexAnalysis/output/figures/Solutions3_4_1.pdf} \subsubsection{3.} We first calculate the Cauchy transform of $f(x) = x/\sqrt{1-x^2}$: \[ \phi(z) = {\I z \over 2 \sqrt{z -1} \sqrt{z+1}} - {\I \over 2} \] This vanishes at $\infty$ and has the correct jump. We then have \[ \I{\cal H}f(x) = \phi^+(x) + \phi^-(x) = -\I \] This implies that (note the sign) \[ \dashint_{-1}^1 {t \over (t-x) \sqrt{1-t^2}} \dt = -\pi \HH f(x) = \pi \] \begin{lstlisting} (*@\HLJLn{f}@*) (*@\HLJLoB{=}@*) (*@\HLJLn{x}@*)(*@\HLJLoB{/}@*)(*@\HLJLnf{sqrt}@*)(*@\HLJLp{(}@*)(*@\HLJLni{1}@*)(*@\HLJLoB{-}@*)(*@\HLJLn{x}@*)(*@\HLJLoB{{\textasciicircum}}@*)(*@\HLJLni{2}@*)(*@\HLJLp{)}@*) (*@\HLJLoB{-}@*)(*@\HLJLn{\ensuremath{\pi}}@*)(*@\HLJLoB{*}@*)(*@\HLJLnf{H}@*)(*@\HLJLp{(}@*)(*@\HLJLn{f}@*)(*@\HLJLp{,}@*) (*@\HLJLnfB{0.1}@*)(*@\HLJLp{)}@*) \end{lstlisting} \begin{lstlisting} 3.141592653589793 \end{lstlisting} \newpage \subsection{Problem 1.2} \subsubsection{1.2.1} From Problem 1.1 part 3, we have a solution: \[ \phi(z) = -{ z \over 2 \sqrt{z -1} \sqrt{z+1}} + {1 \over 2} \] All other solutions are then of the form: \[ \phi(z) + {C \over \sqrt{z-1} \sqrt{z+1}} \] \begin{lstlisting} (*@\HLJLn{C}@*) (*@\HLJLoB{=}@*) (*@\HLJLnf{randn}@*)(*@\HLJLp{()}@*) (*@\HLJLn{\ensuremath{\varphi}}@*) (*@\HLJLoB{=}@*) (*@\HLJLn{z}@*) (*@\HLJLoB{->}@*) (*@\HLJLoB{-}@*)(*@\HLJLn{z}@*)(*@\HLJLoB{/}@*)(*@\HLJLp{(}@*)(*@\HLJLni{2}@*)(*@\HLJLoB{*}@*)(*@\HLJLnf{sqrt}@*)(*@\HLJLp{(}@*)(*@\HLJLn{z}@*)(*@\HLJLoB{-}@*)(*@\HLJLni{1}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{*}@*)(*@\HLJLnf{sqrt}@*)(*@\HLJLp{(}@*)(*@\HLJLn{z}@*)(*@\HLJLoB{+}@*)(*@\HLJLni{1}@*)(*@\HLJLp{))}@*)(*@\HLJLoB{+}@*)(*@\HLJLni{1}@*)(*@\HLJLoB{/}@*)(*@\HLJLni{2}@*) (*@\HLJLoB{+}@*) (*@\HLJLn{C}@*)(*@\HLJLoB{/}@*)(*@\HLJLp{(}@*)(*@\HLJLnf{sqrt}@*)(*@\HLJLp{(}@*)(*@\HLJLn{z}@*)(*@\HLJLoB{-}@*)(*@\HLJLni{1}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{*}@*)(*@\HLJLnf{sqrt}@*)(*@\HLJLp{(}@*)(*@\HLJLn{z}@*)(*@\HLJLoB{+}@*)(*@\HLJLni{1}@*)(*@\HLJLp{))}@*) (*@\HLJLnf{\ensuremath{\varphi}}@*)(*@\HLJLp{(}@*)(*@\HLJLnfB{0.1}@*)(*@\HLJLoB{+}@*)(*@\HLJLnfB{0.0}@*)(*@\HLJLn{im}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{+}@*)(*@\HLJLnf{\ensuremath{\varphi}}@*)(*@\HLJLp{(}@*)(*@\HLJLnfB{0.1}@*)(*@\HLJLoB{-}@*)(*@\HLJLnfB{0.0}@*)(*@\HLJLn{im}@*)(*@\HLJLp{),}@*) (*@\HLJLnf{\ensuremath{\varphi}}@*)(*@\HLJLp{(}@*)(*@\HLJLnfB{1E8}@*)(*@\HLJLp{)}@*) \end{lstlisting} \begin{lstlisting} (1.0 + 0.0im, -1.782207108835652e-8) \end{lstlisting} \newpage \subsubsection{1.2.2} \[ \psi(z) = -2\phi(z) + 1 = { z \over \sqrt{z -1} \sqrt{z+1}} \] satisfies \[ \psi_+(x) + \psi_-(x) = 0, \qquad \psi(\infty) = 1 \] \begin{lstlisting} (*@\HLJLn{C}@*) (*@\HLJLoB{=}@*) (*@\HLJLnf{randn}@*)(*@\HLJLp{()}@*) (*@\HLJLn{\ensuremath{\varphi}}@*) (*@\HLJLoB{=}@*) (*@\HLJLn{z}@*) (*@\HLJLoB{->}@*) (*@\HLJLn{z}@*)(*@\HLJLoB{/}@*)(*@\HLJLp{(}@*)(*@\HLJLnf{sqrt}@*)(*@\HLJLp{(}@*)(*@\HLJLn{z}@*)(*@\HLJLoB{-}@*)(*@\HLJLni{1}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{*}@*)(*@\HLJLnf{sqrt}@*)(*@\HLJLp{(}@*)(*@\HLJLn{z}@*)(*@\HLJLoB{+}@*)(*@\HLJLni{1}@*)(*@\HLJLp{))}@*) (*@\HLJLoB{+}@*) (*@\HLJLn{C}@*)(*@\HLJLoB{/}@*)(*@\HLJLp{(}@*)(*@\HLJLnf{sqrt}@*)(*@\HLJLp{(}@*)(*@\HLJLn{z}@*)(*@\HLJLoB{-}@*)(*@\HLJLni{1}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{*}@*)(*@\HLJLnf{sqrt}@*)(*@\HLJLp{(}@*)(*@\HLJLn{z}@*)(*@\HLJLoB{+}@*)(*@\HLJLni{1}@*)(*@\HLJLp{))}@*) (*@\HLJLnf{\ensuremath{\varphi}}@*)(*@\HLJLp{(}@*)(*@\HLJLnfB{0.1}@*)(*@\HLJLoB{+}@*)(*@\HLJLnfB{0.0}@*)(*@\HLJLn{im}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{+}@*)(*@\HLJLnf{\ensuremath{\varphi}}@*)(*@\HLJLp{(}@*)(*@\HLJLnfB{0.1}@*)(*@\HLJLoB{-}@*)(*@\HLJLnfB{0.0}@*)(*@\HLJLn{im}@*)(*@\HLJLp{),}@*)(*@\HLJLnf{\ensuremath{\varphi}}@*)(*@\HLJLp{(}@*)(*@\HLJLnfB{1E9}@*)(*@\HLJLp{)}@*) \end{lstlisting} \begin{lstlisting} (0.0 + 0.0im, 0.9999999993222088) \end{lstlisting} \newpage \subsubsection{1.2.3} For $f(x) = \sqrt{1-x^2}$, we use the formula \begin{align*} \phi(z) &= {\I \over \sqrt{z - 1} \sqrt{z+1}} \CC[\sqrt{1-\diamond^2} f](z) + {C \over \sqrt{z-1}\sqrt{z+1}}\\ & = {\I \over \sqrt{z - 1} \sqrt{z+1}} \CC[1-\diamond^2](z) + {C \over \sqrt{z-1}\sqrt{z+1}} \end{align*} We already know $\CC1(z)$, and we can deduce $\CC[\diamond^2]$ as follows: try \[ \phi_1(z) = z^2 \CC1(z) = z^2 {\log(z-1) - \log(z+1) \over 2 \pi \I} \] this has the right jump, but blows up at $\infty$ like: \[ x^2 (\log(x-1) - \log(x+1)) = x^2 (\log(1-1/x) - \log(1+1/x) ) = -2 x + O(x^{-1}) \] using \[ \log z = (z-1) - {1\over 2}(z-1)^2 + O(z-1)^3 \] Thus we have \[ \CC[\diamond^2](z) = {z^2 (\log(z-1) - \log(z+1)) + 2 z \over 2 \pi \I} \] and \[ \phi(z) = {\I \over \sqrt{z - 1} \sqrt{z+1}} {(1-z^2)(\log(z-1) - \log(z+1)) - 2 z \over 2 \pi \I} + {C \over \sqrt{z-1}\sqrt{z+1}} \] \emph{Demonstration} Here we see that the Cauchy transform of $x^2$ has the correct formula: \begin{lstlisting} (*@\HLJLn{z}@*) (*@\HLJLoB{=}@*) (*@\HLJLnfB{2.0}@*)(*@\HLJLoB{+}@*)(*@\HLJLnfB{2.0}@*)(*@\HLJLn{im}@*) (*@\HLJLnf{cauchy}@*)(*@\HLJLp{(}@*)(*@\HLJLn{x}@*)(*@\HLJLoB{{\textasciicircum}}@*)(*@\HLJLni{2}@*)(*@\HLJLp{,}@*) (*@\HLJLn{z}@*)(*@\HLJLp{),(}@*)(*@\HLJLn{z}@*)(*@\HLJLoB{{\textasciicircum}}@*)(*@\HLJLni{2}@*)(*@\HLJLoB{*}@*)(*@\HLJLp{(}@*)(*@\HLJLnf{log}@*)(*@\HLJLp{(}@*)(*@\HLJLn{z}@*)(*@\HLJLoB{-}@*)(*@\HLJLni{1}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{-}@*)(*@\HLJLnf{log}@*)(*@\HLJLp{(}@*)(*@\HLJLn{z}@*)(*@\HLJLoB{+}@*)(*@\HLJLni{1}@*)(*@\HLJLp{))}@*)(*@\HLJLoB{+}@*)(*@\HLJLni{2}@*)(*@\HLJLn{z}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{/}@*)(*@\HLJLp{(}@*)(*@\HLJLni{2}@*)(*@\HLJLn{\ensuremath{\pi}}@*)(*@\HLJLoB{*}@*)(*@\HLJLn{im}@*)(*@\HLJLp{)}@*) \end{lstlisting} \begin{lstlisting} (0.0283222937395961 + 0.024377589786690298im, 0.028322293739596032 + 0.0243 7758978669024im) \end{lstlisting} We now see that $\phi$ has the right jumps: \begin{lstlisting} (*@\HLJLn{C}@*) (*@\HLJLoB{=}@*) (*@\HLJLnf{randn}@*)(*@\HLJLp{()}@*) (*@\HLJLn{\ensuremath{\varphi}}@*) (*@\HLJLoB{=}@*) (*@\HLJLn{z}@*) (*@\HLJLoB{->}@*) (*@\HLJLn{im}@*)(*@\HLJLoB{/}@*)(*@\HLJLp{(}@*)(*@\HLJLnf{sqrt}@*)(*@\HLJLp{(}@*)(*@\HLJLn{z}@*)(*@\HLJLoB{-}@*)(*@\HLJLni{1}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{*}@*)(*@\HLJLnf{sqrt}@*)(*@\HLJLp{(}@*)(*@\HLJLn{z}@*)(*@\HLJLoB{+}@*)(*@\HLJLni{1}@*)(*@\HLJLp{))}@*) (*@\HLJLoB{*}@*) (*@\HLJLp{((}@*)(*@\HLJLni{1}@*)(*@\HLJLoB{-}@*)(*@\HLJLn{z}@*)(*@\HLJLoB{{\textasciicircum}}@*)(*@\HLJLni{2}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{*}@*)(*@\HLJLp{(}@*)(*@\HLJLnf{log}@*)(*@\HLJLp{(}@*)(*@\HLJLn{z}@*)(*@\HLJLoB{-}@*)(*@\HLJLni{1}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{-}@*)(*@\HLJLnf{log}@*)(*@\HLJLp{(}@*)(*@\HLJLn{z}@*)(*@\HLJLoB{+}@*)(*@\HLJLni{1}@*)(*@\HLJLp{))}@*)(*@\HLJLoB{-}@*)(*@\HLJLni{2}@*)(*@\HLJLn{z}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{/}@*)(*@\HLJLp{(}@*)(*@\HLJLni{2}@*)(*@\HLJLn{\ensuremath{\pi}}@*)(*@\HLJLoB{*}@*)(*@\HLJLn{im}@*)(*@\HLJLp{)}@*) (*@\HLJLoB{+}@*) (*@\HLJLn{C}@*)(*@\HLJLoB{/}@*)(*@\HLJLp{(}@*)(*@\HLJLnf{sqrt}@*)(*@\HLJLp{(}@*)(*@\HLJLn{z}@*)(*@\HLJLoB{-}@*)(*@\HLJLni{1}@*)(*@\HLJLp{)}@*)(*@\HLJLnf{sqrt}@*)(*@\HLJLp{(}@*)(*@\HLJLn{z}@*)(*@\HLJLoB{+}@*)(*@\HLJLni{1}@*)(*@\HLJLp{))}@*) (*@\HLJLnf{\ensuremath{\varphi}}@*)(*@\HLJLp{(}@*)(*@\HLJLnfB{0.1}@*)(*@\HLJLoB{+}@*)(*@\HLJLnfB{0.0}@*)(*@\HLJLn{im}@*)(*@\HLJLp{)}@*) (*@\HLJLoB{+}@*) (*@\HLJLnf{\ensuremath{\varphi}}@*)(*@\HLJLp{(}@*)(*@\HLJLnfB{0.1}@*)(*@\HLJLoB{-}@*)(*@\HLJLnfB{0.0}@*)(*@\HLJLn{im}@*)(*@\HLJLp{)}@*) (*@\HLJLoB{-}@*) (*@\HLJLnf{sqrt}@*)(*@\HLJLp{(}@*)(*@\HLJLni{1}@*)(*@\HLJLoB{-}@*)(*@\HLJLnfB{0.1}@*)(*@\HLJLoB{{\textasciicircum}}@*)(*@\HLJLni{2}@*)(*@\HLJLp{)}@*) \end{lstlisting} \begin{lstlisting} 1.1102230246251565e-16 + 0.0im \end{lstlisting} Finally, it vanishes at infinity: \begin{lstlisting} (*@\HLJLnf{\ensuremath{\varphi}}@*)(*@\HLJLp{(}@*)(*@\HLJLnfB{1E5}@*)(*@\HLJLp{)}@*) \end{lstlisting} \begin{lstlisting} -6.764623255449203e-7 - 0.0im \end{lstlisting} \subsubsection{1.2.4} Let $f(x) = {1 \over 1+x^2}$. From Problem 1.1 part 1 we know \[ \CC\left[{\sqrt{1-\diamond^2}\over 1 + \diamond^2}\right] (z) = {\sqrt{z-1} \sqrt{z+1} \over 2\I(1 + z^2)} + {\sqrt{\I -1} \sqrt{\I+1} \over 4} { 1 \over z - \I} - {\sqrt{-\I -1} \sqrt{-\I+1} \over 4} { 1 \over z + \I} \] hence from the solution formula we have \[ \phi(z) = {1 \over 2(1 + z^2)} + {\sqrt{\I -1} \sqrt{\I+1} \I \over 4\sqrt{z-1} \sqrt{z+1}} { 1 \over z - \I} - {\sqrt{-\I -1} \sqrt{-\I+1} \I \over 4\sqrt{z-1} \sqrt{z+1}} { 1 \over z + \I} + {C \over \sqrt{z-1} \sqrt{z+1}} \] But we want something stronger: that $\phi(z) = O(z^{-2})$. To accomplish this, we need to choose $C$. Fortunately, I made the problem easy as every term apart from the last one is already $O(z^{-2})$, so choose $C = 0$: \begin{lstlisting} (*@\HLJLn{\ensuremath{\varphi}}@*) (*@\HLJLoB{=}@*) (*@\HLJLn{z}@*) (*@\HLJLoB{->}@*) (*@\HLJLni{1}@*)(*@\HLJLoB{/}@*)(*@\HLJLp{(}@*)(*@\HLJLni{2}@*)(*@\HLJLoB{*}@*)(*@\HLJLp{(}@*)(*@\HLJLni{1}@*)(*@\HLJLoB{+}@*)(*@\HLJLn{z}@*)(*@\HLJLoB{{\textasciicircum}}@*)(*@\HLJLni{2}@*)(*@\HLJLp{))}@*) (*@\HLJLoB{+}@*) (*@\HLJLnf{sqrt}@*)(*@\HLJLp{(}@*)(*@\HLJLn{im}@*)(*@\HLJLoB{-}@*)(*@\HLJLni{1}@*)(*@\HLJLp{)}@*)(*@\HLJLnf{sqrt}@*)(*@\HLJLp{(}@*)(*@\HLJLn{im}@*)(*@\HLJLoB{+}@*)(*@\HLJLni{1}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{*}@*)(*@\HLJLn{im}@*)(*@\HLJLoB{/}@*)(*@\HLJLp{(}@*)(*@\HLJLni{4}@*)(*@\HLJLnf{sqrt}@*)(*@\HLJLp{(}@*)(*@\HLJLn{z}@*)(*@\HLJLoB{-}@*)(*@\HLJLni{1}@*)(*@\HLJLp{)}@*)(*@\HLJLnf{sqrt}@*)(*@\HLJLp{(}@*)(*@\HLJLn{z}@*)(*@\HLJLoB{+}@*)(*@\HLJLni{1}@*)(*@\HLJLp{))}@*)(*@\HLJLoB{*}@*)(*@\HLJLni{1}@*)(*@\HLJLoB{/}@*)(*@\HLJLp{(}@*)(*@\HLJLn{z}@*)(*@\HLJLoB{-}@*)(*@\HLJLn{im}@*)(*@\HLJLp{)}@*) (*@\HLJLoB{-}@*) (*@\HLJLnf{sqrt}@*)(*@\HLJLp{(}@*)(*@\HLJLoB{-}@*)(*@\HLJLn{im}@*)(*@\HLJLoB{-}@*)(*@\HLJLni{1}@*)(*@\HLJLp{)}@*)(*@\HLJLnf{sqrt}@*)(*@\HLJLp{(}@*)(*@\HLJLoB{-}@*)(*@\HLJLn{im}@*)(*@\HLJLoB{+}@*)(*@\HLJLni{1}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{*}@*)(*@\HLJLn{im}@*)(*@\HLJLoB{/}@*)(*@\HLJLp{(}@*)(*@\HLJLni{4}@*)(*@\HLJLnf{sqrt}@*)(*@\HLJLp{(}@*)(*@\HLJLn{z}@*)(*@\HLJLoB{-}@*)(*@\HLJLni{1}@*)(*@\HLJLp{)}@*)(*@\HLJLnf{sqrt}@*)(*@\HLJLp{(}@*)(*@\HLJLn{z}@*)(*@\HLJLoB{+}@*)(*@\HLJLni{1}@*)(*@\HLJLp{))}@*)(*@\HLJLoB{*}@*)(*@\HLJLni{1}@*)(*@\HLJLoB{/}@*)(*@\HLJLp{(}@*)(*@\HLJLn{z}@*)(*@\HLJLoB{+}@*)(*@\HLJLn{im}@*)(*@\HLJLp{)}@*) (*@\HLJLnf{\ensuremath{\varphi}}@*)(*@\HLJLp{(}@*)(*@\HLJLnfB{1E5}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{*}@*)(*@\HLJLnfB{1E5}@*) \end{lstlisting} \begin{lstlisting} -2.071067812011923e-6 + 0.0im \end{lstlisting} We see also that it has the right jump: \begin{lstlisting} (*@\HLJLnf{\ensuremath{\varphi}}@*)(*@\HLJLp{(}@*)(*@\HLJLnfB{0.1}@*)(*@\HLJLoB{+}@*)(*@\HLJLnfB{0.0}@*)(*@\HLJLn{im}@*)(*@\HLJLp{)}@*) (*@\HLJLoB{+}@*) (*@\HLJLnf{\ensuremath{\varphi}}@*)(*@\HLJLp{(}@*)(*@\HLJLnfB{0.1}@*)(*@\HLJLoB{-}@*)(*@\HLJLnfB{0.0}@*)(*@\HLJLn{im}@*)(*@\HLJLp{),}@*)(*@\HLJLni{1}@*)(*@\HLJLoB{/}@*)(*@\HLJLp{(}@*)(*@\HLJLni{1}@*)(*@\HLJLoB{+}@*)(*@\HLJLnfB{0.1}@*)(*@\HLJLoB{{\textasciicircum}}@*)(*@\HLJLni{2}@*)(*@\HLJLp{)}@*) \end{lstlisting} \begin{lstlisting} (0.9900990099009901 + 0.0im, 0.9900990099009901) \end{lstlisting} \subsection{Problem 1.3} \begin{itemize} \item[1. ] From the Hilbert formula, we know that the general solution of $\HH u = f$ is \end{itemize} \[ u(x) = {-1 \over \sqrt{1 - x^2}}\HH \left[{ f(\diamond) \sqrt{1-\diamond^2} }\right](x) - {C \over \sqrt{1-x^2}} \] Plugging in $f(x) = x/\sqrt{1-x^2}$ means we need to calculate \[ \HH \left[{\diamond}\right](x) \] We do so by first finding the Cauchy transform. Consider \[ \phi_1(z) = z \CC 1(z) = z {\log(z-1) - \log(z+1) \over 2 \pi \I} \] This has the right jump: \[ \phi_1^+(x) - \phi_1^-(x) = x \] but doesn't decay at $\infty$: \begin{align*} x {\log(x-1) - \log(x+1) \over 2 \pi \I} = x {\log x + \log(1-1/x) - \log x -\log(1+1/x) \over 2 \pi \I} \\ = -x { 2 \over x 2 \pi \I} = -{1 \over \I \pi} \end{align*} But this means that \[ \phi(z) = \phi_1(z) + {1 \over \I \pi} = z {\log(z-1) - \log(z+1) \over 2 \pi \I} + {1 \over \I \pi} \] Decays and has the right jump, hence is $\CC[\diamond](z)$. \begin{lstlisting} (*@\HLJLn{t}@*) (*@\HLJLoB{=}@*) (*@\HLJLnf{Fun}@*)(*@\HLJLp{()}@*) (*@\HLJLn{z}@*) (*@\HLJLoB{=}@*) (*@\HLJLnfB{2.0}@*)(*@\HLJLoB{+}@*)(*@\HLJLnfB{2.0}@*)(*@\HLJLn{im}@*) (*@\HLJLnf{cauchy}@*)(*@\HLJLp{(}@*)(*@\HLJLn{t}@*)(*@\HLJLp{,}@*) (*@\HLJLn{z}@*)(*@\HLJLp{),}@*) (*@\HLJLn{z}@*)(*@\HLJLoB{*}@*)(*@\HLJLp{(}@*)(*@\HLJLnf{log}@*)(*@\HLJLp{(}@*)(*@\HLJLn{z}@*)(*@\HLJLoB{-}@*)(*@\HLJLni{1}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{-}@*)(*@\HLJLnf{log}@*)(*@\HLJLp{(}@*)(*@\HLJLn{z}@*)(*@\HLJLoB{+}@*)(*@\HLJLni{1}@*)(*@\HLJLp{))}@*)(*@\HLJLoB{/}@*)(*@\HLJLp{(}@*)(*@\HLJLni{2}@*)(*@\HLJLn{\ensuremath{\pi}}@*)(*@\HLJLoB{*}@*)(*@\HLJLn{im}@*)(*@\HLJLp{)}@*) (*@\HLJLoB{+}@*) (*@\HLJLni{1}@*)(*@\HLJLoB{/}@*)(*@\HLJLp{(}@*)(*@\HLJLn{im}@*)(*@\HLJLoB{*}@*)(*@\HLJLn{\ensuremath{\pi}}@*)(*@\HLJLp{)}@*) \end{lstlisting} \begin{lstlisting} (0.013174970881571602 - 0.0009861759882264494im, 0.013174970881571569 - 0.0 009861759882264232im) \end{lstlisting} Therefore, we have \[ \HH[\diamond](x) = -\I (\CC^+ + \CC^-) \diamond(x) = -x {\log(1-x) - \log(1+x) \over \pi} -{2 \over \pi} \] \begin{lstlisting} (*@\HLJLn{x}@*) (*@\HLJLoB{=}@*) (*@\HLJLnfB{0.1}@*) (*@\HLJLnf{H}@*)(*@\HLJLp{(}@*)(*@\HLJLn{t}@*)(*@\HLJLp{,}@*)(*@\HLJLn{x}@*)(*@\HLJLp{),}@*) (*@\HLJLoB{-}@*)(*@\HLJLn{x}@*)(*@\HLJLoB{*}@*)(*@\HLJLp{(}@*)(*@\HLJLnf{log}@*)(*@\HLJLp{(}@*)(*@\HLJLni{1}@*)(*@\HLJLoB{-}@*)(*@\HLJLn{x}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{-}@*)(*@\HLJLnf{log}@*)(*@\HLJLp{(}@*)(*@\HLJLni{1}@*)(*@\HLJLoB{+}@*)(*@\HLJLn{x}@*)(*@\HLJLp{))}@*)(*@\HLJLoB{/}@*)(*@\HLJLp{(}@*)(*@\HLJLn{\ensuremath{\pi}}@*)(*@\HLJLp{)}@*) (*@\HLJLoB{-}@*) (*@\HLJLni{2}@*)(*@\HLJLoB{/}@*)(*@\HLJLn{\ensuremath{\pi}}@*) \end{lstlisting} \begin{lstlisting} (-0.6302322257442835, -0.6302322257442834) \end{lstlisting} Therefore, we get \[ u(x) = - {x(\log(1-x) - \log(1+x))+2 \over \pi\sqrt{1-x^2}} - {C \over \sqrt{1-x^2}} \] This can be verified in Mathematica via \begin{verbatim} NIntegrate[-(( x (Log[1 - x] - Log[1 + x]) + 2)/(Pi Sqrt[1 - x^2] (x - 0.1))), {x, -1, 0.1, 1}, PrincipalValue -> True]/Pi \end{verbatim} \begin{itemize} \item[2. ] Following the procedure of multiplying $\CC[\sqrt{1-\diamond^2}](z)$ by $1/(2+z)$ and subtracting off the pole at $z=-2$, we first find: \end{itemize} \begin{align*} \CC\left[{\sqrt{1-\diamond^2} \over 2+\diamond}\right](z)& = {\sqrt{z-1}\sqrt{z+1} - z \over 2\I(2+z)} -{\sqrt{-2-1}_+ \sqrt{-2+1}_+ +2 \over 2\I(2+z)}\\ & = {\sqrt{z-1}\sqrt{z+1} - z \over 2\I(2+z)} +{ \sqrt{3} -2 \over 2\I(2+z)} \end{align*} \begin{lstlisting} (*@\HLJLn{t}@*) (*@\HLJLoB{=}@*) (*@\HLJLnf{Fun}@*)(*@\HLJLp{()}@*) (*@\HLJLn{z}@*) (*@\HLJLoB{=}@*) (*@\HLJLnfB{2.0}@*)(*@\HLJLoB{+}@*)(*@\HLJLnfB{2.0}@*)(*@\HLJLn{im}@*) (*@\HLJLnf{cauchy}@*)(*@\HLJLp{(}@*)(*@\HLJLnf{sqrt}@*)(*@\HLJLp{(}@*)(*@\HLJLni{1}@*)(*@\HLJLoB{-}@*)(*@\HLJLn{t}@*)(*@\HLJLoB{{\textasciicircum}}@*)(*@\HLJLni{2}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{/}@*)(*@\HLJLp{(}@*)(*@\HLJLni{2}@*)(*@\HLJLoB{+}@*)(*@\HLJLn{t}@*)(*@\HLJLp{),}@*) (*@\HLJLn{z}@*)(*@\HLJLp{),}@*) (*@\HLJLp{(}@*)(*@\HLJLnf{sqrt}@*)(*@\HLJLp{(}@*)(*@\HLJLn{z}@*)(*@\HLJLoB{-}@*)(*@\HLJLni{1}@*)(*@\HLJLp{)}@*)(*@\HLJLnf{sqrt}@*)(*@\HLJLp{(}@*)(*@\HLJLn{z}@*)(*@\HLJLoB{+}@*)(*@\HLJLni{1}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{-}@*)(*@\HLJLn{z}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{/}@*)(*@\HLJLp{(}@*)(*@\HLJLni{2}@*)(*@\HLJLn{im}@*)(*@\HLJLoB{*}@*)(*@\HLJLp{(}@*)(*@\HLJLni{2}@*)(*@\HLJLoB{+}@*)(*@\HLJLn{z}@*)(*@\HLJLp{))}@*) (*@\HLJLoB{+}@*) (*@\HLJLp{(}@*)(*@\HLJLnf{sqrt}@*)(*@\HLJLp{(}@*)(*@\HLJLni{3}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{-}@*)(*@\HLJLni{2}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{/}@*)(*@\HLJLp{(}@*)(*@\HLJLni{2}@*)(*@\HLJLn{im}@*)(*@\HLJLoB{*}@*)(*@\HLJLp{(}@*)(*@\HLJLn{z}@*)(*@\HLJLoB{+}@*)(*@\HLJLni{2}@*)(*@\HLJLp{))}@*) \end{lstlisting} \begin{lstlisting} (0.03230545315801244 + 0.032449695183223826im, 0.032305453158012455 + 0.032 449695183223784im) \end{lstlisting} Therefore, calculating $-\I(\CC^+ + \CC^-)$ we find that \[ \HH\left[{\sqrt{1-\diamond^2} \over 2+\diamond}\right](z) = {x\over 2+x} -{ \sqrt{3} -2 \over 2+x} \] \begin{lstlisting} (*@\HLJLn{x}@*) (*@\HLJLoB{=}@*) (*@\HLJLnfB{0.1}@*) (*@\HLJLnf{H}@*)(*@\HLJLp{(}@*)(*@\HLJLnf{sqrt}@*)(*@\HLJLp{(}@*)(*@\HLJLni{1}@*)(*@\HLJLoB{-}@*)(*@\HLJLn{t}@*)(*@\HLJLoB{{\textasciicircum}}@*)(*@\HLJLni{2}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{/}@*)(*@\HLJLp{(}@*)(*@\HLJLni{2}@*)(*@\HLJLoB{+}@*)(*@\HLJLn{t}@*)(*@\HLJLp{),}@*) (*@\HLJLn{x}@*)(*@\HLJLp{),}@*) (*@\HLJLn{x}@*)(*@\HLJLoB{/}@*)(*@\HLJLp{(}@*)(*@\HLJLni{2}@*)(*@\HLJLoB{+}@*)(*@\HLJLn{x}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{-}@*)(*@\HLJLp{(}@*)(*@\HLJLnf{sqrt}@*)(*@\HLJLp{(}@*)(*@\HLJLni{3}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{-}@*)(*@\HLJLni{2}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{/}@*)(*@\HLJLp{(}@*)(*@\HLJLni{2}@*)(*@\HLJLoB{+}@*)(*@\HLJLn{x}@*)(*@\HLJLp{)}@*) \end{lstlisting} \begin{lstlisting} (0.17521390115767735, 0.17521390115767752) \end{lstlisting} \newpage Thus the general solution is \[ u(x) = -{1 \over \sqrt{1-x^2}} \left( {x\over 2+x} -{ \sqrt{3} -2 \over 2+x} + C \right) \] We need to choose $C$ so this is bounded at the right-endpoint: In other words, \[ u(x) = -{1 \over \sqrt{1-x^2}} \left( {x\over 2+x} -{ \sqrt{3} -2 \over 2+x} +{ \sqrt{3} -3 \over 3} \right) \] \begin{lstlisting} (*@\HLJLn{u}@*) (*@\HLJLoB{=}@*) (*@\HLJLoB{-}@*)(*@\HLJLp{(}@*)(*@\HLJLn{t}@*)(*@\HLJLoB{/}@*)(*@\HLJLp{(}@*)(*@\HLJLni{2}@*)(*@\HLJLoB{+}@*)(*@\HLJLn{t}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{-}@*)(*@\HLJLp{(}@*)(*@\HLJLnf{sqrt}@*)(*@\HLJLp{(}@*)(*@\HLJLni{3}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{-}@*)(*@\HLJLni{2}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{/}@*)(*@\HLJLp{(}@*)(*@\HLJLni{2}@*)(*@\HLJLoB{+}@*)(*@\HLJLn{t}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{+}@*)(*@\HLJLp{(}@*)(*@\HLJLnf{sqrt}@*)(*@\HLJLp{(}@*)(*@\HLJLni{3}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{-}@*)(*@\HLJLni{3}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{/}@*)(*@\HLJLni{3}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{/}@*)(*@\HLJLnf{sqrt}@*)(*@\HLJLp{(}@*)(*@\HLJLni{1}@*)(*@\HLJLoB{-}@*)(*@\HLJLn{t}@*)(*@\HLJLoB{{\textasciicircum}}@*)(*@\HLJLni{2}@*)(*@\HLJLp{)}@*) (*@\HLJLnf{plot}@*)(*@\HLJLp{(}@*)(*@\HLJLn{u}@*)(*@\HLJLp{;}@*) (*@\HLJLn{ylims}@*)(*@\HLJLoB{=}@*)(*@\HLJLp{(}@*)(*@\HLJLoB{-}@*)(*@\HLJLni{5}@*)(*@\HLJLp{,}@*)(*@\HLJLni{5}@*)(*@\HLJLp{))}@*) \end{lstlisting} \includegraphics[width=\linewidth]{C:/Users/mfaso/OneDrive/Documents/GitHub/M3M6AppliedComplexAnalysis/output/figures/Solutions3_17_1.pdf} \begin{lstlisting} (*@\HLJLn{x}@*) (*@\HLJLoB{=}@*) (*@\HLJLnfB{0.1}@*) (*@\HLJLnf{H}@*)(*@\HLJLp{(}@*)(*@\HLJLn{u}@*)(*@\HLJLp{,}@*)(*@\HLJLn{x}@*)(*@\HLJLp{)}@*) (*@\HLJLp{,}@*) (*@\HLJLni{1}@*)(*@\HLJLoB{/}@*)(*@\HLJLp{(}@*)(*@\HLJLni{2}@*)(*@\HLJLoB{+}@*)(*@\HLJLn{x}@*)(*@\HLJLp{)}@*) \end{lstlisting} \begin{lstlisting} (0.47619047619047533, 0.47619047619047616) \end{lstlisting} \subsection{Problem 2.1} Doing the change of variables $\zeta = b s$ we have \[ \log(ab) = \int_1^{ab} {\D \zeta \over \zeta} = \int_{1/b}^a {\D s \over s} \] if $\gamma$ does not surround the origin, we have \[ 0 = \oint_\gamma {\D s \over s} = \left[\int_1^{1/b} + \int_{1/b}^a + \int_a^1\right] {\D s \over s} \] which implies \[ \log(ab) = \left[-\int_a^1 -\int_1^{1/b} \right] {\D s \over s} = \log a - \log {1 \over b} = \log a + \log b \] Here's a picture: \begin{lstlisting} (*@\HLJLn{a}@*) (*@\HLJLoB{=}@*) (*@\HLJLnfB{1.0}@*)(*@\HLJLoB{+}@*)(*@\HLJLnfB{2.0}@*)(*@\HLJLn{im}@*) (*@\HLJLn{b}@*) (*@\HLJLoB{=}@*) (*@\HLJLoB{-}@*)(*@\HLJLnfB{1.0}@*)(*@\HLJLoB{-}@*)(*@\HLJLnfB{2.0}@*)(*@\HLJLn{im}@*) (*@\HLJLnd{@show}@*) (*@\HLJLnf{log}@*)(*@\HLJLp{(}@*)(*@\HLJLn{a}@*)(*@\HLJLoB{*}@*)(*@\HLJLn{b}@*)(*@\HLJLp{)}@*) (*@\HLJLnd{@show}@*) (*@\HLJLnf{log}@*)(*@\HLJLp{(}@*)(*@\HLJLn{a}@*)(*@\HLJLp{)}@*) (*@\HLJLoB{+}@*) (*@\HLJLnf{log}@*)(*@\HLJLp{(}@*)(*@\HLJLn{b}@*)(*@\HLJLp{)}@*) (*@\HLJLnf{scatter}@*)(*@\HLJLp{([}@*)(*@\HLJLnf{real}@*)(*@\HLJLp{(}@*)(*@\HLJLni{1}@*)(*@\HLJLoB{/}@*)(*@\HLJLn{b}@*)(*@\HLJLp{)],}@*) (*@\HLJLp{[}@*)(*@\HLJLnf{imag}@*)(*@\HLJLp{(}@*)(*@\HLJLni{1}@*)(*@\HLJLoB{/}@*)(*@\HLJLn{b}@*)(*@\HLJLp{)];}@*) (*@\HLJLn{label}@*)(*@\HLJLoB{=}@*)(*@\HLJLs{"{}1/b"{}}@*)(*@\HLJLp{)}@*) (*@\HLJLnf{scatter!}@*)(*@\HLJLp{([}@*)(*@\HLJLnf{real}@*)(*@\HLJLp{(}@*)(*@\HLJLn{a}@*)(*@\HLJLp{)],}@*) (*@\HLJLp{[}@*)(*@\HLJLnf{imag}@*)(*@\HLJLp{(}@*)(*@\HLJLn{a}@*)(*@\HLJLp{)];}@*) (*@\HLJLn{label}@*)(*@\HLJLoB{=}@*)(*@\HLJLs{"{}a"{}}@*)(*@\HLJLp{)}@*) (*@\HLJLnf{scatter!}@*)(*@\HLJLp{([}@*)(*@\HLJLnfB{0.0}@*)(*@\HLJLp{],}@*) (*@\HLJLp{[}@*)(*@\HLJLnfB{0.0}@*)(*@\HLJLp{];}@*) (*@\HLJLn{label}@*)(*@\HLJLoB{=}@*)(*@\HLJLs{"{}0"{}}@*)(*@\HLJLp{)}@*) (*@\HLJLnf{plot!}@*)(*@\HLJLp{(}@*)(*@\HLJLnf{Segment}@*)(*@\HLJLp{(}@*)(*@\HLJLni{1}@*)(*@\HLJLp{,}@*) (*@\HLJLni{1}@*)(*@\HLJLoB{/}@*)(*@\HLJLn{b}@*)(*@\HLJLp{)}@*) (*@\HLJLoB{\ensuremath{\cup}}@*) (*@\HLJLnf{Segment}@*)(*@\HLJLp{(}@*)(*@\HLJLni{1}@*)(*@\HLJLoB{/}@*)(*@\HLJLn{b}@*)(*@\HLJLp{,}@*) (*@\HLJLn{a}@*)(*@\HLJLp{)}@*) (*@\HLJLoB{\ensuremath{\cup}}@*) (*@\HLJLnf{Segment}@*)(*@\HLJLp{(}@*)(*@\HLJLn{a}@*)(*@\HLJLp{,}@*) (*@\HLJLni{1}@*)(*@\HLJLp{);}@*) (*@\HLJLn{label}@*)(*@\HLJLoB{=}@*)(*@\HLJLs{"{}contour"{}}@*)(*@\HLJLp{)}@*) \end{lstlisting} \begin{lstlisting} log(a * b) = 1.6094379124341003 - 0.9272952180016122im log(a) + log(b) = 1.6094379124341003 - 0.9272952180016123im \end{lstlisting} \includegraphics[width=\linewidth]{C:/Users/mfaso/OneDrive/Documents/GitHub/M3M6AppliedComplexAnalysis/output/figures/Solutions3_19_1.pdf} If it surrounds the origin counbter-clockwise, that is, it has positive orientation, we have $2\pi \I = \oint_\gamma {\D s \over s}$, which shoes that \[ \log(ab) = 2 \pi \I - \left[\int_a^1 +\int_1^{1/b} \right] {\D s \over s} = \log a + \log b + 2\pi \I \] and a similar result when counter clockwise. \begin{lstlisting} (*@\HLJLn{a}@*) (*@\HLJLoB{=}@*) (*@\HLJLnfB{1.0}@*)(*@\HLJLoB{+}@*)(*@\HLJLnfB{2.0}@*)(*@\HLJLn{im}@*) (*@\HLJLn{b}@*) (*@\HLJLoB{=}@*) (*@\HLJLoB{-}@*)(*@\HLJLnfB{2.0}@*)(*@\HLJLoB{+}@*)(*@\HLJLnfB{2.0}@*)(*@\HLJLn{im}@*) (*@\HLJLnd{@show}@*) (*@\HLJLnf{log}@*)(*@\HLJLp{(}@*)(*@\HLJLn{a}@*)(*@\HLJLoB{*}@*)(*@\HLJLn{b}@*)(*@\HLJLp{)}@*) (*@\HLJLnd{@show}@*) (*@\HLJLnf{log}@*)(*@\HLJLp{(}@*)(*@\HLJLn{a}@*)(*@\HLJLp{)}@*) (*@\HLJLoB{+}@*) (*@\HLJLnf{log}@*)(*@\HLJLp{(}@*)(*@\HLJLn{b}@*)(*@\HLJLp{)}@*) (*@\HLJLoB{-}@*) (*@\HLJLni{2}@*)(*@\HLJLn{\ensuremath{\pi}}@*)(*@\HLJLoB{*}@*)(*@\HLJLn{im}@*) (*@\HLJLnf{scatter}@*)(*@\HLJLp{([}@*)(*@\HLJLnf{real}@*)(*@\HLJLp{(}@*)(*@\HLJLni{1}@*)(*@\HLJLoB{/}@*)(*@\HLJLn{b}@*)(*@\HLJLp{)],}@*) (*@\HLJLp{[}@*)(*@\HLJLnf{imag}@*)(*@\HLJLp{(}@*)(*@\HLJLni{1}@*)(*@\HLJLoB{/}@*)(*@\HLJLn{b}@*)(*@\HLJLp{)];}@*) (*@\HLJLn{label}@*)(*@\HLJLoB{=}@*)(*@\HLJLs{"{}1/b"{}}@*)(*@\HLJLp{)}@*) (*@\HLJLnf{scatter!}@*)(*@\HLJLp{([}@*)(*@\HLJLnf{real}@*)(*@\HLJLp{(}@*)(*@\HLJLn{a}@*)(*@\HLJLp{)],}@*) (*@\HLJLp{[}@*)(*@\HLJLnf{imag}@*)(*@\HLJLp{(}@*)(*@\HLJLn{a}@*)(*@\HLJLp{)];}@*) (*@\HLJLn{label}@*)(*@\HLJLoB{=}@*)(*@\HLJLs{"{}a"{}}@*)(*@\HLJLp{)}@*) (*@\HLJLnf{scatter!}@*)(*@\HLJLp{([}@*)(*@\HLJLnfB{0.0}@*)(*@\HLJLp{],}@*) (*@\HLJLp{[}@*)(*@\HLJLnfB{0.0}@*)(*@\HLJLp{];}@*) (*@\HLJLn{label}@*)(*@\HLJLoB{=}@*)(*@\HLJLs{"{}0"{}}@*)(*@\HLJLp{)}@*) (*@\HLJLnf{plot!}@*)(*@\HLJLp{(}@*)(*@\HLJLnf{Segment}@*)(*@\HLJLp{(}@*)(*@\HLJLni{1}@*)(*@\HLJLp{,}@*) (*@\HLJLni{1}@*)(*@\HLJLoB{/}@*)(*@\HLJLn{b}@*)(*@\HLJLp{)}@*) (*@\HLJLoB{\ensuremath{\cup}}@*) (*@\HLJLnf{Segment}@*)(*@\HLJLp{(}@*)(*@\HLJLni{1}@*)(*@\HLJLoB{/}@*)(*@\HLJLn{b}@*)(*@\HLJLp{,}@*) (*@\HLJLn{a}@*)(*@\HLJLp{)}@*) (*@\HLJLoB{\ensuremath{\cup}}@*) (*@\HLJLnf{Segment}@*)(*@\HLJLp{(}@*)(*@\HLJLn{a}@*)(*@\HLJLp{,}@*) (*@\HLJLni{1}@*)(*@\HLJLp{);}@*) (*@\HLJLn{label}@*)(*@\HLJLoB{=}@*)(*@\HLJLs{"{}contour"{}}@*)(*@\HLJLp{)}@*) \end{lstlisting} \begin{lstlisting} log(a * b) = 1.8444397270569681 - 2.819842099193151im (log(a) + log(b)) - (2(*@\ensuremath{\pi}@*() * im = 1.844439727056968 - 2.819842099193151im \end{lstlisting} \includegraphics[width=\linewidth]{C:/Users/mfaso/OneDrive/Documents/GitHub/M3M6AppliedComplexAnalysis/output/figures/Solutions3_20_1.pdf} If the contour passes through the origin, there are three possibility: \begin{itemize} \item[1. ] $[a,1]$ contains zero, hence $a < 0$ \item[2. ] \[ [1,1/b] \] contains zero, hence $b < 0$ \item[3. ] \[ [1/b, a] \] contains zero, which can only be true if $a b < 0$ by considering the equation of the line segment. \end{itemize} 1. In the case where $a < 0$ and $b < 0$ (and hence $a b > 0$), perturbing $a$ above and $b$ below or vice versa avoids $\gamma$ winding around zero, so we have \[ \log(a b) = \log_+ a + \log_- b = \log_- a + \log_+ b = \log_+ a + \log_+ b - 2 \pi \I = \log_- a + \log_- b + 2 \pi \I \] \begin{lstlisting} (*@\HLJLn{a}@*) (*@\HLJLoB{=}@*) (*@\HLJLoB{-}@*)(*@\HLJLnfB{2.0}@*) (*@\HLJLn{b}@*) (*@\HLJLoB{=}@*) (*@\HLJLoB{-}@*)(*@\HLJLnfB{3.0}@*) (*@\HLJLnd{@show}@*) (*@\HLJLnf{log}@*)(*@\HLJLp{(}@*)(*@\HLJLn{a}@*)(*@\HLJLoB{*}@*)(*@\HLJLn{b}@*)(*@\HLJLp{)}@*) (*@\HLJLnd{@show}@*) (*@\HLJLnf{log}@*)(*@\HLJLp{(}@*)(*@\HLJLn{a}@*)(*@\HLJLoB{+}@*)(*@\HLJLnfB{0.0}@*)(*@\HLJLn{im}@*)(*@\HLJLp{)}@*) (*@\HLJLoB{+}@*) (*@\HLJLnf{log}@*)(*@\HLJLp{(}@*)(*@\HLJLn{b}@*)(*@\HLJLoB{-}@*)(*@\HLJLnfB{0.0}@*)(*@\HLJLn{im}@*)(*@\HLJLp{)}@*) (*@\HLJLnd{@show}@*) (*@\HLJLnf{log}@*)(*@\HLJLp{(}@*)(*@\HLJLn{a}@*)(*@\HLJLoB{-}@*)(*@\HLJLnfB{0.0}@*)(*@\HLJLn{im}@*)(*@\HLJLp{)}@*) (*@\HLJLoB{+}@*) (*@\HLJLnf{log}@*)(*@\HLJLp{(}@*)(*@\HLJLn{b}@*)(*@\HLJLoB{+}@*)(*@\HLJLnfB{0.0}@*)(*@\HLJLn{im}@*)(*@\HLJLp{)}@*) (*@\HLJLnd{@show}@*) (*@\HLJLnf{log}@*)(*@\HLJLp{(}@*)(*@\HLJLn{a}@*)(*@\HLJLoB{-}@*)(*@\HLJLnfB{0.0}@*)(*@\HLJLn{im}@*)(*@\HLJLp{)}@*) (*@\HLJLoB{+}@*) (*@\HLJLnf{log}@*)(*@\HLJLp{(}@*)(*@\HLJLn{b}@*)(*@\HLJLoB{-}@*)(*@\HLJLnfB{0.0}@*)(*@\HLJLn{im}@*)(*@\HLJLp{)}@*) (*@\HLJLoB{+}@*) (*@\HLJLni{2}@*)(*@\HLJLn{\ensuremath{\pi}}@*)(*@\HLJLoB{*}@*)(*@\HLJLn{im}@*) (*@\HLJLnd{@show}@*) (*@\HLJLnf{log}@*)(*@\HLJLp{(}@*)(*@\HLJLn{a}@*)(*@\HLJLoB{+}@*)(*@\HLJLnfB{0.0}@*)(*@\HLJLn{im}@*)(*@\HLJLp{)}@*) (*@\HLJLoB{+}@*) (*@\HLJLnf{log}@*)(*@\HLJLp{(}@*)(*@\HLJLn{b}@*)(*@\HLJLoB{+}@*)(*@\HLJLnfB{0.0}@*)(*@\HLJLn{im}@*)(*@\HLJLp{)}@*) (*@\HLJLoB{-}@*) (*@\HLJLni{2}@*)(*@\HLJLn{\ensuremath{\pi}}@*)(*@\HLJLoB{*}@*)(*@\HLJLn{im}@*)(*@\HLJLp{;}@*) \end{lstlisting} \begin{lstlisting} log(a * b) = 1.791759469228055 log(a + 0.0im) + log(b - 0.0im) = 1.791759469228055 + 0.0im log(a - 0.0im) + log(b + 0.0im) = 1.791759469228055 + 0.0im log(a - 0.0im) + log(b - 0.0im) + (2(*@\ensuremath{\pi}@*() * im = 1.791759469228055 + 0.0im (log(a + 0.0im) + log(b + 0.0im)) - (2(*@\ensuremath{\pi}@*() * im = 1.791759469228055 + 0.0im \end{lstlisting} In the case where $a < 0$ and $b > 0$, then $a b < 0$, but we can perturb $a$ above/below to get \[ \log_\pm(a b) = \log_\pm a + \log b \] (and by symmetry, the equivalent holds for $b < 0$ and $a > 0$.) \begin{lstlisting} (*@\HLJLn{a}@*) (*@\HLJLoB{=}@*) (*@\HLJLoB{-}@*)(*@\HLJLnfB{2.0}@*) (*@\HLJLn{b}@*) (*@\HLJLoB{=}@*) (*@\HLJLnfB{3.0}@*) (*@\HLJLnd{@show}@*) (*@\HLJLnf{log}@*)(*@\HLJLp{(}@*)(*@\HLJLn{a}@*)(*@\HLJLoB{*}@*)(*@\HLJLn{b}@*) (*@\HLJLoB{+}@*)(*@\HLJLnfB{0.0}@*)(*@\HLJLn{im}@*)(*@\HLJLp{)}@*) (*@\HLJLnd{@show}@*) (*@\HLJLnf{log}@*)(*@\HLJLp{(}@*)(*@\HLJLn{a}@*)(*@\HLJLoB{+}@*)(*@\HLJLnfB{0.0}@*)(*@\HLJLn{im}@*)(*@\HLJLp{)}@*) (*@\HLJLoB{+}@*) (*@\HLJLnf{log}@*)(*@\HLJLp{(}@*)(*@\HLJLn{b}@*)(*@\HLJLp{);}@*) (*@\HLJLnd{@show}@*) (*@\HLJLnf{log}@*)(*@\HLJLp{(}@*)(*@\HLJLn{a}@*)(*@\HLJLoB{*}@*)(*@\HLJLn{b}@*) (*@\HLJLoB{-}@*)(*@\HLJLnfB{0.0}@*)(*@\HLJLn{im}@*)(*@\HLJLp{)}@*) (*@\HLJLnd{@show}@*) (*@\HLJLnf{log}@*)(*@\HLJLp{(}@*)(*@\HLJLn{a}@*)(*@\HLJLoB{-}@*)(*@\HLJLnfB{0.0}@*)(*@\HLJLn{im}@*)(*@\HLJLp{)}@*) (*@\HLJLoB{+}@*) (*@\HLJLnf{log}@*)(*@\HLJLp{(}@*)(*@\HLJLn{b}@*)(*@\HLJLp{);}@*) \end{lstlisting} \begin{lstlisting} log(a * b + 0.0im) = 1.791759469228055 + 3.141592653589793im log(a + 0.0im) + log(b) = 1.791759469228055 + 3.141592653589793im log(a * b - 0.0im) = 1.791759469228055 - 3.141592653589793im log(a - 0.0im) + log(b) = 1.791759469228055 - 3.141592653589793im \end{lstlisting} In the case where $a < 0$, if $\Im b > 0$ we can perturb $a$ below so that $\gamma$ does not contain zero, giving us \[ \log(ab) = \log_- a + \log b \] similarly, if $\Im b < 0$ we can perturb $a$ above. \begin{lstlisting} (*@\HLJLn{a}@*) (*@\HLJLoB{=}@*) (*@\HLJLoB{-}@*)(*@\HLJLnfB{2.0}@*) (*@\HLJLn{b}@*) (*@\HLJLoB{=}@*) (*@\HLJLnfB{3.0}@*) (*@\HLJLoB{+}@*) (*@\HLJLn{im}@*) (*@\HLJLnd{@show}@*) (*@\HLJLnf{log}@*)(*@\HLJLp{(}@*)(*@\HLJLn{a}@*)(*@\HLJLoB{*}@*)(*@\HLJLn{b}@*)(*@\HLJLp{)}@*) (*@\HLJLnd{@show}@*) (*@\HLJLnf{log}@*)(*@\HLJLp{(}@*)(*@\HLJLn{a}@*)(*@\HLJLoB{-}@*)(*@\HLJLnfB{0.0}@*)(*@\HLJLn{im}@*)(*@\HLJLp{)}@*) (*@\HLJLoB{+}@*) (*@\HLJLnf{log}@*)(*@\HLJLp{(}@*)(*@\HLJLn{b}@*)(*@\HLJLp{);}@*) (*@\HLJLn{b}@*) (*@\HLJLoB{=}@*) (*@\HLJLnfB{3.0}@*) (*@\HLJLoB{+}@*) (*@\HLJLn{im}@*)(*@\HLJLp{;}@*) (*@\HLJLnd{@show}@*) (*@\HLJLnf{log}@*)(*@\HLJLp{(}@*)(*@\HLJLn{a}@*)(*@\HLJLoB{*}@*)(*@\HLJLn{b}@*)(*@\HLJLp{)}@*) (*@\HLJLnd{@show}@*) (*@\HLJLnf{log}@*)(*@\HLJLp{(}@*)(*@\HLJLn{a}@*)(*@\HLJLoB{+}@*)(*@\HLJLnfB{0.0}@*)(*@\HLJLn{im}@*)(*@\HLJLp{)}@*) (*@\HLJLoB{+}@*) (*@\HLJLnf{log}@*)(*@\HLJLp{(}@*)(*@\HLJLn{b}@*)(*@\HLJLp{);}@*) \end{lstlisting} \begin{lstlisting} log(a * b) = 1.8444397270569681 - 2.819842099193151im log(a - 0.0im) + log(b) = 1.8444397270569683 - 2.819842099193151im log(a * b) = 1.8444397270569681 - 2.819842099193151im log(a + 0.0im) + log(b) = 1.8444397270569683 + 3.4633432079864352im \end{lstlisting} 2. In this case, swap the role of $a$ and $b$ and use the answers for $a < 0$. 3. Finally, we have the case $a b < 0$ and neither $a$ nor $b$ is real. Note that \[ ab = (a_x + \I a_y) (b_x + \I b_y) = a_x b_x - a_y b_y + \I(a_x b_y + a_yb_x) \] It follows if $b_x > 0$ we have \[ (ab)_+ = a_+ b \] and if $b_x < 0$ we have \[ (ab)_+ = a_- b \] \begin{lstlisting} (*@\HLJLn{a}@*) (*@\HLJLoB{=}@*) (*@\HLJLoB{-}@*)(*@\HLJLnfB{1.0}@*) (*@\HLJLoB{+}@*) (*@\HLJLnfB{1.0}@*)(*@\HLJLn{im}@*) (*@\HLJLn{b}@*) (*@\HLJLoB{=}@*) (*@\HLJLnfB{1.0}@*) (*@\HLJLoB{+}@*) (*@\HLJLnfB{1.0}@*)(*@\HLJLn{im}@*) (*@\HLJLnd{@show}@*) (*@\HLJLnf{log}@*)(*@\HLJLp{(}@*)(*@\HLJLn{a}@*)(*@\HLJLoB{*}@*)(*@\HLJLn{b}@*) (*@\HLJLoB{+}@*) (*@\HLJLnf{eps}@*)(*@\HLJLp{()}@*)(*@\HLJLn{im}@*)(*@\HLJLp{)}@*) (*@\HLJLnd{@show}@*) (*@\HLJLnf{log}@*)(*@\HLJLp{((}@*)(*@\HLJLn{a}@*)(*@\HLJLoB{+}@*)(*@\HLJLnf{eps}@*)(*@\HLJLp{()}@*)(*@\HLJLn{im}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{*}@*)(*@\HLJLn{b}@*)(*@\HLJLp{)}@*) (*@\HLJLn{a}@*) (*@\HLJLoB{=}@*) (*@\HLJLnfB{1.0}@*) (*@\HLJLoB{+}@*) (*@\HLJLnfB{1.0}@*)(*@\HLJLn{im}@*) (*@\HLJLn{b}@*) (*@\HLJLoB{=}@*) (*@\HLJLoB{-}@*)(*@\HLJLnfB{1.0}@*) (*@\HLJLoB{+}@*) (*@\HLJLnfB{1.0}@*)(*@\HLJLn{im}@*) (*@\HLJLnd{@show}@*) (*@\HLJLnf{log}@*)(*@\HLJLp{(}@*)(*@\HLJLn{a}@*)(*@\HLJLoB{*}@*)(*@\HLJLn{b}@*) (*@\HLJLoB{+}@*) (*@\HLJLnf{eps}@*)(*@\HLJLp{()}@*)(*@\HLJLn{im}@*)(*@\HLJLp{)}@*) (*@\HLJLnd{@show}@*) (*@\HLJLnf{log}@*)(*@\HLJLp{((}@*)(*@\HLJLn{a}@*)(*@\HLJLoB{-}@*)(*@\HLJLnf{eps}@*)(*@\HLJLp{()}@*)(*@\HLJLn{im}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{*}@*)(*@\HLJLn{b}@*)(*@\HLJLp{)}@*) \end{lstlisting} \begin{lstlisting} log(a * b + eps() * im) = 0.6931471805599453 + 3.141592653589793im log((a + eps() * im) * b) = 0.6931471805599453 + 3.141592653589793im log(a * b + eps() * im) = 0.6931471805599453 + 3.141592653589793im log((a - eps() * im) * b) = 0.6931471805599452 + 3.141592653589793im 0.6931471805599452 + 3.141592653589793im \end{lstlisting} We can use this perturbation to reduce to the previous cases. For example, if $a = 1 + \I$ and $b = -1 + \I$, pertubing $ab$ above causes $a$ to be perturbed above, which causes the contour to surround the origin clockwise, hence we have \[ \log_+(ab) = \log(a)_+b = \log a b - 2 \pi \I \] \begin{lstlisting} (*@\HLJLn{a}@*) (*@\HLJLoB{=}@*) (*@\HLJLnfB{1.0}@*) (*@\HLJLoB{+}@*) (*@\HLJLnfB{1.0}@*)(*@\HLJLn{im}@*) (*@\HLJLn{b}@*) (*@\HLJLoB{=}@*) (*@\HLJLoB{-}@*)(*@\HLJLnfB{1.0}@*) (*@\HLJLoB{+}@*) (*@\HLJLnfB{1.0}@*)(*@\HLJLn{im}@*) (*@\HLJLnd{@show}@*) (*@\HLJLnf{log}@*)(*@\HLJLp{(}@*)(*@\HLJLn{a}@*)(*@\HLJLoB{*}@*)(*@\HLJLn{b}@*) (*@\HLJLoB{-}@*) (*@\HLJLnf{eps}@*)(*@\HLJLp{()}@*)(*@\HLJLn{im}@*)(*@\HLJLp{)}@*) (*@\HLJLnd{@show}@*) (*@\HLJLnf{log}@*)(*@\HLJLp{(}@*)(*@\HLJLn{a}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{+}@*)(*@\HLJLnf{log}@*)(*@\HLJLp{(}@*)(*@\HLJLn{b}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{-}@*)(*@\HLJLni{2}@*)(*@\HLJLn{\ensuremath{\pi}}@*)(*@\HLJLoB{*}@*)(*@\HLJLn{im}@*)(*@\HLJLp{;}@*) \end{lstlisting} \begin{lstlisting} log(a * b - eps() * im) = 0.6931471805599453 - 3.141592653589793im (log(a) + log(b)) - (2(*@\ensuremath{\pi}@*() * im = 0.6931471805599453 - 3.141592653589793im \end{lstlisting} \subsection{Problem 2.2} Use the contour $\gamma(t) = 1 + t(z-1)$ to reduce it to a normal integral: $\overline{\log z } = \overline{\int_1^z {1 \over \zeta} \D \zeta} = \overline{\int_0^1 {(z-1) \over 1+(z-1) t} \dt} = \int_0^1 {(\bar z-1) \over 1+(\bar z-1) t} \dt = \int_1^{\bar z} {\D \zeta \over \zeta} = \log \bar z.$ We then have, since the contour from $1$ to $1/(\bar z)$ to $z$ never surrounds the origin since both $\Im z$ and $\Im 1/(\bar z)$ have the same sign, we have \[ 2 \Re \log z = \log z + \overline{\log z} = \log z + \log \bar z = \log z \bar z = \log |z|^2 = 2 \log |z| \] On the other hand, we have, where the contour of integration is chosen to be to the right of zero and then we do the change of variables $\zeta = |z| \E^{\I \theta}$ \[ 2 \Im \log z = \log z - \log \bar z = \int_{\bar z}^z {\D \zeta \over \zeta} = \I \int_{-\arg z}^{\arg z} \D \theta = 2 \I \arg z \] \subsection{Problem 2.3} We first show that it is analytic on $(-\infty,0)$. To do this, we need to show that the limit from above equals the limit from below: for $x < 0$ we have $\log_1^+ x -\log_1^- x = \log_+x - \log_- x -2 \pi \I = 0$ Then for $x > 0$ and using $\log_1^\pm(x) = \lim_{\epsilon\rightarrow 0} \log(x\pm \I \epsilon)$ we find \[ \log_1^+(x) - \log_1^-x = \log x- \log x- 2\pi \I = -2 \pi \I \] \emph{Demonstration} Here we see that the following is the analytic continuation: \begin{lstlisting} (*@\HLJLn{log1}@*) (*@\HLJLoB{=}@*) (*@\HLJLn{z}@*) (*@\HLJLoB{->}@*) (*@\HLJLk{begin}@*) (*@\HLJLk{if}@*) (*@\HLJLnf{imag}@*)(*@\HLJLp{(}@*)(*@\HLJLn{z}@*)(*@\HLJLp{)}@*) (*@\HLJLoB{>}@*) (*@\HLJLni{0}@*) (*@\HLJLnf{log}@*)(*@\HLJLp{(}@*)(*@\HLJLn{z}@*)(*@\HLJLp{)}@*) (*@\HLJLk{elseif}@*) (*@\HLJLnf{imag}@*)(*@\HLJLp{(}@*)(*@\HLJLn{z}@*)(*@\HLJLp{)}@*) (*@\HLJLoB{==}@*) (*@\HLJLni{0}@*) (*@\HLJLoB{{\&}{\&}}@*) (*@\HLJLnf{real}@*)(*@\HLJLp{(}@*)(*@\HLJLn{z}@*)(*@\HLJLp{)}@*) (*@\HLJLoB{<}@*) (*@\HLJLni{0}@*) (*@\HLJLnf{log}@*)(*@\HLJLp{(}@*)(*@\HLJLn{z}@*) (*@\HLJLoB{+}@*) (*@\HLJLnfB{0.0}@*)(*@\HLJLn{im}@*)(*@\HLJLp{)}@*) (*@\HLJLk{elseif}@*) (*@\HLJLnf{imag}@*)(*@\HLJLp{(}@*)(*@\HLJLn{z}@*)(*@\HLJLp{)}@*) (*@\HLJLoB{<}@*) (*@\HLJLni{0}@*) (*@\HLJLnf{log}@*)(*@\HLJLp{(}@*)(*@\HLJLn{z}@*)(*@\HLJLp{)}@*) (*@\HLJLoB{+}@*) (*@\HLJLni{2}@*)(*@\HLJLn{\ensuremath{\pi}}@*)(*@\HLJLoB{*}@*)(*@\HLJLn{im}@*) (*@\HLJLk{else}@*) (*@\HLJLnf{error}@*)(*@\HLJLp{(}@*)(*@\HLJLs{"{}log1}@*) (*@\HLJLs{not}@*) (*@\HLJLs{defined}@*) (*@\HLJLs{on}@*) (*@\HLJLs{real}@*) (*@\HLJLs{axis"{}}@*)(*@\HLJLp{)}@*) (*@\HLJLk{end}@*) (*@\HLJLk{end}@*) (*@\HLJLnf{phaseplot}@*)(*@\HLJLp{(}@*)(*@\HLJLoB{-}@*)(*@\HLJLnfB{3..3}@*)(*@\HLJLp{,}@*) (*@\HLJLoB{-}@*)(*@\HLJLnfB{3..3}@*)(*@\HLJLp{,}@*) (*@\HLJLn{log1}@*)(*@\HLJLp{)}@*) \end{lstlisting} \includegraphics[width=\linewidth]{C:/Users/mfaso/OneDrive/Documents/GitHub/M3M6AppliedComplexAnalysis/output/figures/Solutions3_26_1.pdf} \subsection{Problem 3.1} \begin{itemize} \item[1. ] Because it's absolutely integrable, we can exchange derivatives and integrals to determine \end{itemize} \[ {\D \CC f \over \D z} = {1 \over 2 \pi \I} \oint {f(\zeta)\over (\zeta-z)^2} \D \zeta \] \begin{itemize} \item[2. ] There are two different possible approaches: \begin{itemize} \item the subtract and add back in technique: since $f$ is analytic for $z$ near $\zeta$, we can write \end{itemize} \end{itemize} \[ \CC f(z) = {1 \over 2 \pi \I} \oint {f(\zeta)-f(z) \over \zeta-z} \D \zeta + f(z) \CC 1(z) \] Therefore \[ \CC^+ f(\zeta) - \CC^- f(\zeta) = f(\zeta)( \CC^+ 1(\zeta) - \CC^- 1(\zeta)) \] But we know (using Cauchy's integral formula / Residue calculus) \[ \CC 1(z) = \begin{cases} 1 & |z| < 1 \\ 0 & |z| > 1 \end{cases} \] hence $(\CC^+-\CC^-)1(\zeta) = 1$ \begin{itemize} \item Since $f$ is analytic, we have for any radius $R > 1$ but inside the annulus \end{itemize} \[ \CC^+ f(\zeta) = {1 \over 2 \pi \I} \oint_{|\zeta| = R} {f(\zeta) \over \zeta -z} \D\zeta \] Similarly, for $\CC^-f(\zeta)$ with any radius $r < 1$ but inside the annulus. Therfore, \[ \CC^+ f(\zeta) - \CC^- f(\zeta) = {1 \over 2 \pi \I} \left[\oint_{|\zeta| = R} - \oint_{|\zeta| = r} \right] {f(\zeta) \over \zeta -z} \D\zeta \] Deforming the contour and using Cauchy-integral formula gives the result. \begin{itemize} \item[3. ] This follow since ${1 \over \zeta - z} \rightarrow 0$ uniformly. \end{itemize} \subsection{Problem 3.2} Suppose we have another solution $\phi$ and consider $\psi(z) = \phi(z) - \CC f(z)$. Then on the circle we have \[ \psi_+(\zeta) - \psi_-(\zeta) = \phi_+(\zeta) - \CC_+f(\zeta) - \phi_-(\zeta) + \CC_+f(\zeta) = f(\zeta)-f(\zeta) = 0 \] Thus $\psi$ is entire, and since it decays at infinity, it must be zero by Liouville's theorem. \newpage \subsection{Problem 3.3} When $k \geq 0$, we have from 3.1 and 3.2 \[ \CC[\diamond^k](z) =\begin{cases} z^k & |z| < 1 \\ 0 & |z| > 1 \end{cases} \] when $k < 0$ since $\CC[\diamond^k]^+(\zeta) - \CC[\diamond^k]^-(\zeta) = \zeta^k - 0 = \zeta^k$. we similarly have \[ \CC[\diamond^k](z) =\begin{cases} 0 & |z| < 1 \\ -z^k & |z| > 1 \end{cases} \] Therefore, \[ \Im \CC^-[\diamond^k](\zeta) =\begin{cases} 0 & k \geq 0 \\ -{\zeta^k - \zeta^{-k} \over 2 \I} & k < 0 \end{cases} \] and \[ \Re \CC^-[\diamond^k](\zeta) =\begin{cases} 0 & k \geq 0 \\ -{\zeta^k + \zeta^{-k} \over 2} & k < 0 \end{cases} \] \newpage \hfill \\ \newpage \subsection{Problem 3.4} Express the solution outside the circle as \[ v(x,y) = \Im ( \E^{-\I \theta} z + \CC f(z)) \] for a to-be-determined $f$. On the circle, this reduces to \[ \Im \CC^- f(\zeta) = -\cos \theta {\zeta - \zeta^{-1} \over 2 \I} + \sin \theta {\zeta + \zeta^{-1} \over 2} \] Unlike the real case, we can include imaginary coefficients, thus the solution is \[ f(\zeta) = (\cos \theta + \I \sin \theta) \zeta^{-1} \] and thus the full solution is \[ v(x,y) = \Im ( \E^{-\I \theta} z - \E^{\I \theta} z^{-1})) \] \begin{lstlisting} (*@\HLJLn{\ensuremath{\theta}}@*) (*@\HLJLoB{=}@*) (*@\HLJLnfB{0.1}@*) (*@\HLJLn{v}@*) (*@\HLJLoB{=}@*) (*@\HLJLp{(}@*)(*@\HLJLn{x}@*)(*@\HLJLp{,}@*)(*@\HLJLn{y}@*)(*@\HLJLp{)}@*) (*@\HLJLoB{->}@*) (*@\HLJLn{x}@*)(*@\HLJLoB{{\textasciicircum}}@*)(*@\HLJLni{2}@*) (*@\HLJLoB{+}@*) (*@\HLJLn{y}@*)(*@\HLJLoB{{\textasciicircum}}@*)(*@\HLJLni{2}@*) (*@\HLJLoB{<}@*) (*@\HLJLni{1}@*) (*@\HLJLoB{?}@*) (*@\HLJLni{0}@*) (*@\HLJLoB{:}@*) (*@\HLJLnf{imag}@*)(*@\HLJLp{(}@*)(*@\HLJLnf{exp}@*)(*@\HLJLp{(}@*)(*@\HLJLoB{-}@*)(*@\HLJLn{im}@*)(*@\HLJLoB{*}@*)(*@\HLJLn{\ensuremath{\theta}}@*)(*@\HLJLp{)}@*) (*@\HLJLoB{*}@*) (*@\HLJLp{(}@*)(*@\HLJLn{x}@*)(*@\HLJLoB{+}@*)(*@\HLJLn{im}@*)(*@\HLJLoB{*}@*)(*@\HLJLn{y}@*)(*@\HLJLp{)}@*) (*@\HLJLoB{+}@*) (*@\HLJLnf{exp}@*)(*@\HLJLp{(}@*)(*@\HLJLn{im}@*)(*@\HLJLoB{*}@*)(*@\HLJLn{\ensuremath{\theta}}@*)(*@\HLJLp{)}@*) (*@\HLJLoB{*}@*) (*@\HLJLp{(}@*)(*@\HLJLn{x}@*)(*@\HLJLoB{+}@*)(*@\HLJLn{im}@*)(*@\HLJLoB{*}@*)(*@\HLJLn{y}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{{\textasciicircum}}@*)(*@\HLJLp{(}@*)(*@\HLJLoB{-}@*)(*@\HLJLni{1}@*)(*@\HLJLp{))}@*) (*@\HLJLn{xx}@*) (*@\HLJLoB{=}@*) (*@\HLJLoB{-}@*)(*@\HLJLni{8}@*)(*@\HLJLoB{:}@*)(*@\HLJLnfB{0.01}@*)(*@\HLJLoB{:}@*)(*@\HLJLni{8}@*)(*@\HLJLp{;}@*) (*@\HLJLn{yy}@*) (*@\HLJLoB{=}@*) (*@\HLJLoB{-}@*)(*@\HLJLni{5}@*)(*@\HLJLoB{:}@*)(*@\HLJLnfB{0.01}@*)(*@\HLJLoB{:}@*)(*@\HLJLni{5}@*) (*@\HLJLnf{contour}@*)(*@\HLJLp{(}@*)(*@\HLJLn{xx}@*)(*@\HLJLp{,}@*) (*@\HLJLn{yy}@*)(*@\HLJLp{,}@*) (*@\HLJLn{v}@*)(*@\HLJLoB{.}@*)(*@\HLJLp{(}@*)(*@\HLJLn{xx}@*)(*@\HLJLoB{{\textquotesingle}}@*)(*@\HLJLp{,}@*) (*@\HLJLn{yy}@*)(*@\HLJLp{);}@*) (*@\HLJLn{nlevels}@*)(*@\HLJLoB{=}@*)(*@\HLJLni{100}@*)(*@\HLJLp{,}@*) (*@\HLJLn{ratio}@*)(*@\HLJLoB{=}@*)(*@\HLJLnfB{1.0}@*)(*@\HLJLp{)}@*) (*@\HLJLnf{plot!}@*)(*@\HLJLp{(}@*)(*@\HLJLnf{Circle}@*)(*@\HLJLp{();}@*) (*@\HLJLn{color}@*)(*@\HLJLoB{=:}@*)(*@\HLJLn{black}@*)(*@\HLJLp{,}@*) (*@\HLJLn{legend}@*)(*@\HLJLoB{=}@*)(*@\HLJLkc{false}@*)(*@\HLJLp{)}@*) \end{lstlisting} \includegraphics[width=\linewidth]{C:/Users/mfaso/OneDrive/Documents/GitHub/M3M6AppliedComplexAnalysis/output/figures/Solutions3_27_1.pdf} \#\# Problem 4.1 \[ z^\alpha \] has the limits $z_\pm^\alpha = \E^{\pm \I \pi \alpha} |z|^\alpha$, thus choose $\alpha = -{\theta \over 2\pi}$ where if we take $0 < \theta < 2\pi$ we have $0 < \alpha < 1$ (the case $\theta = 0$ and $\theta = \pi$ are covered by the Cauchy transform, that is ). Then consider \[ \kappa(z) = (z-1)^{-\alpha} (z+1)^{\alpha-1} \] which has weaker than pole singularities and satisfies $\kappa(z) \sim z^{-1}$. For $-1 < x < 1$ it has the right jump \begin{align*} \kappa_+(x) &= (x-1)_+^{-\alpha} (x+1)^{\alpha - 1} = \E^{-\I \pi \alpha} (1-x)^{-\alpha} (x+1)^{\alpha-1} = \E^{-2\I \pi \alpha} (x-1)_-^{-\alpha} (x+1)^{\alpha-1}\\ & = \E^{-2 \I \pi \alpha} \kappa_-(x)= \E^{\I \theta} \kappa_-(x) \end{align*} and for $x < -1$ it has the jump \[ \kappa_+(x) = (x-1)_+^{-\alpha} (x+1)_+^{\alpha-1} = \E^{-\I \pi \alpha}\E^{\I \pi (\alpha-1)} (1-x)^{-\alpha} (-1-x)^{\alpha-1} = \kappa_-(x) \] hence $\kappa$ is analytic. We need to show this times a constant spans the entire space. Suppose we have another solution $\tilde \kappa$ and consider $r(z) = {\tilde \kappa(z) \over \kappa(z)}$. Note by construction that $\kappa$ has no zeros. Then \[ r_+(x) = {\tilde\kappa_+(x) \over \kappa_+(x)} = {\tilde\kappa_-(x) \over \kappa_-(x)} = r_-(x) \] hence $r$ is analytic on $(-1,1)$. It has weaker than pole singularities because $\kappa(z)^{-1}$ is actually bounded at $\pm 1$. Therefore $r$ is bounded and entire, and thus must be a constant $r(z) \equiv r$, and thence $\tilde \kappa(z) = r \kappa(z)$. \begin{lstlisting} (*@\HLJLn{\ensuremath{\theta}}@*) (*@\HLJLoB{=}@*)(*@\HLJLnfB{2.3}@*) (*@\HLJLn{\ensuremath{\alpha}}@*) (*@\HLJLoB{=}@*) (*@\HLJLoB{-}@*)(*@\HLJLn{\ensuremath{\theta}}@*)(*@\HLJLoB{/}@*)(*@\HLJLp{(}@*)(*@\HLJLni{2}@*)(*@\HLJLn{\ensuremath{\pi}}@*)(*@\HLJLp{)}@*) (*@\HLJLn{\ensuremath{\kappa}}@*) (*@\HLJLoB{=}@*) (*@\HLJLn{z}@*) (*@\HLJLoB{->}@*) (*@\HLJLp{(}@*)(*@\HLJLn{z}@*)(*@\HLJLoB{-}@*)(*@\HLJLni{1}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{{\textasciicircum}}@*)(*@\HLJLp{(}@*)(*@\HLJLoB{-}@*)(*@\HLJLn{\ensuremath{\alpha}}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{*}@*)(*@\HLJLp{(}@*)(*@\HLJLn{z}@*)(*@\HLJLoB{+}@*)(*@\HLJLni{1}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{{\textasciicircum}}@*)(*@\HLJLp{(}@*)(*@\HLJLn{\ensuremath{\alpha}}@*)(*@\HLJLoB{-}@*)(*@\HLJLni{1}@*)(*@\HLJLp{)}@*) (*@\HLJLnf{\ensuremath{\kappa}}@*)(*@\HLJLp{(}@*)(*@\HLJLnfB{0.1}@*)(*@\HLJLoB{+}@*)(*@\HLJLnfB{0.0}@*)(*@\HLJLn{im}@*)(*@\HLJLp{)}@*) (*@\HLJLoB{-}@*) (*@\HLJLnf{exp}@*)(*@\HLJLp{(}@*)(*@\HLJLn{im}@*)(*@\HLJLoB{*}@*)(*@\HLJLn{\ensuremath{\theta}}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{*}@*)(*@\HLJLnf{\ensuremath{\kappa}}@*)(*@\HLJLp{(}@*)(*@\HLJLnfB{0.1}@*)(*@\HLJLoB{-}@*)(*@\HLJLnfB{0.0}@*)(*@\HLJLn{im}@*)(*@\HLJLp{),}@*)(*@\HLJLnf{\ensuremath{\kappa}}@*)(*@\HLJLp{(}@*)(*@\HLJLnfB{100.0}@*)(*@\HLJLp{)}@*) \end{lstlisting} \begin{lstlisting} (0.0 + 1.1102230246251565e-16im, 0.00982876598532333) \end{lstlisting} \begin{lstlisting} (*@\HLJLnf{phaseplot}@*)(*@\HLJLp{(}@*)(*@\HLJLoB{-}@*)(*@\HLJLnfB{3..3}@*)(*@\HLJLp{,}@*) (*@\HLJLoB{-}@*)(*@\HLJLnfB{3..3}@*)(*@\HLJLp{,}@*) (*@\HLJLn{\ensuremath{\kappa}}@*)(*@\HLJLp{)}@*) \end{lstlisting} \includegraphics[width=\linewidth]{C:/Users/mfaso/OneDrive/Documents/GitHub/M3M6AppliedComplexAnalysis/output/figures/Solutions3_29_1.pdf} \subsection{Problem 4.2} We want to mimic the solution of $\phi_+(x) + \phi_-(x)$. So take \[ \phi(z) = \kappa(z) \CC\br[{f \over \kappa_+}](z) =\E^{-\I \theta/2} (z-1)^{-\alpha}(z+1)^{\alpha-1} \CC[f (1-x)^{\alpha}(1+x)^{1-\alpha}](z) \] This has the jump \begin{align*} \phi_+(x) - \E^{\I \theta}\phi_-(x) & = \kappa_+(z) \CC_+\br[{f \over \kappa_+}](x) - \E^{\I \theta}\kappa_-(z)\CC_-\br[{f \over \kappa_+}](x) \\ & = \kappa_+(x) \pr({\CC_+\br[{f \over \kappa_+}](x) - \CC_-\br[{f \over \kappa_+}](x) }) = f(x) \end{align*} Thus the general solution is $\phi(z) + C \kappa(z)$. \begin{lstlisting} (*@\HLJLn{\ensuremath{\theta}}@*) (*@\HLJLoB{=}@*)(*@\HLJLnfB{2.3}@*) (*@\HLJLn{\ensuremath{\alpha}}@*) (*@\HLJLoB{=}@*) (*@\HLJLoB{-}@*)(*@\HLJLn{\ensuremath{\theta}}@*)(*@\HLJLoB{/}@*)(*@\HLJLp{(}@*)(*@\HLJLni{2}@*)(*@\HLJLn{\ensuremath{\pi}}@*)(*@\HLJLp{)}@*) (*@\HLJLn{\ensuremath{\kappa}}@*) (*@\HLJLoB{=}@*) (*@\HLJLn{z}@*) (*@\HLJLoB{->}@*) (*@\HLJLp{(}@*)(*@\HLJLn{z}@*)(*@\HLJLoB{-}@*)(*@\HLJLni{1}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{{\textasciicircum}}@*)(*@\HLJLp{(}@*)(*@\HLJLoB{-}@*)(*@\HLJLn{\ensuremath{\alpha}}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{*}@*)(*@\HLJLp{(}@*)(*@\HLJLn{z}@*)(*@\HLJLoB{+}@*)(*@\HLJLni{1}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{{\textasciicircum}}@*)(*@\HLJLp{(}@*)(*@\HLJLn{\ensuremath{\alpha}}@*)(*@\HLJLoB{-}@*)(*@\HLJLni{1}@*)(*@\HLJLp{)}@*) (*@\HLJLn{x}@*) (*@\HLJLoB{=}@*) (*@\HLJLnf{Fun}@*)(*@\HLJLp{()}@*) (*@\HLJLn{\ensuremath{\kappa}\ensuremath{\_+}}@*) (*@\HLJLoB{=}@*) (*@\HLJLnf{exp}@*)(*@\HLJLp{(}@*)(*@\HLJLn{im}@*)(*@\HLJLoB{*}@*)(*@\HLJLn{\ensuremath{\theta}}@*)(*@\HLJLoB{/}@*)(*@\HLJLni{2}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{*}@*)(*@\HLJLp{(}@*)(*@\HLJLni{1}@*)(*@\HLJLoB{-}@*)(*@\HLJLn{x}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{{\textasciicircum}}@*)(*@\HLJLp{(}@*)(*@\HLJLoB{-}@*)(*@\HLJLn{\ensuremath{\alpha}}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{*}@*)(*@\HLJLp{(}@*)(*@\HLJLn{x}@*)(*@\HLJLoB{+}@*)(*@\HLJLni{1}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{{\textasciicircum}}@*)(*@\HLJLp{(}@*)(*@\HLJLn{\ensuremath{\alpha}}@*)(*@\HLJLoB{-}@*)(*@\HLJLni{1}@*)(*@\HLJLp{)}@*) (*@\HLJLn{f}@*) (*@\HLJLoB{=}@*) (*@\HLJLnf{Fun}@*)(*@\HLJLp{(}@*)(*@\HLJLn{exp}@*)(*@\HLJLp{)}@*) (*@\HLJLn{z}@*) (*@\HLJLoB{=}@*) (*@\HLJLni{2}@*)(*@\HLJLoB{+}@*)(*@\HLJLn{im}@*) (*@\HLJLn{\ensuremath{\varphi}}@*) (*@\HLJLoB{=}@*) (*@\HLJLn{z}@*) (*@\HLJLoB{->}@*) (*@\HLJLnf{\ensuremath{\kappa}}@*)(*@\HLJLp{(}@*)(*@\HLJLn{z}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{*}@*)(*@\HLJLnf{cauchy}@*)(*@\HLJLp{(}@*)(*@\HLJLn{f}@*)(*@\HLJLoB{/}@*)(*@\HLJLn{\ensuremath{\kappa}\ensuremath{\_+}}@*)(*@\HLJLp{,}@*) (*@\HLJLn{z}@*)(*@\HLJLp{)}@*) (*@\HLJLnf{\ensuremath{\varphi}}@*)(*@\HLJLp{(}@*)(*@\HLJLnfB{0.1}@*)(*@\HLJLoB{+}@*)(*@\HLJLnfB{0.0}@*)(*@\HLJLn{im}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{-}@*)(*@\HLJLnf{exp}@*)(*@\HLJLp{(}@*)(*@\HLJLn{im}@*)(*@\HLJLoB{*}@*)(*@\HLJLn{\ensuremath{\theta}}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{*}@*)(*@\HLJLnf{\ensuremath{\varphi}}@*)(*@\HLJLp{(}@*)(*@\HLJLnfB{0.1}@*)(*@\HLJLoB{-}@*)(*@\HLJLnfB{0.0}@*)(*@\HLJLn{im}@*)(*@\HLJLp{)}@*) (*@\HLJLoB{-}@*) (*@\HLJLnf{f}@*)(*@\HLJLp{(}@*)(*@\HLJLnfB{0.1}@*)(*@\HLJLp{)}@*) \end{lstlisting} \begin{lstlisting} -1.3322676295501878e-15 - 2.220446049250313e-16im \end{lstlisting} \subsection{Problem 4.3} Note for $x < 0$ \[ x_+^{\I \beta} = \E^{\I \beta \log_+ x} = \E^{\I \beta \log_- x - 2\pi \beta} = \E^{-2 \pi \beta} x_-^{\I \beta} \] \begin{lstlisting} (*@\HLJLn{\ensuremath{\beta}}@*) (*@\HLJLoB{=}@*) (*@\HLJLnfB{2.3}@*)(*@\HLJLp{;}@*) (*@\HLJLn{x}@*) (*@\HLJLoB{=}@*) (*@\HLJLoB{-}@*)(*@\HLJLnfB{2.0}@*) (*@\HLJLp{(}@*)(*@\HLJLn{x}@*)(*@\HLJLoB{+}@*)(*@\HLJLnfB{0.0}@*)(*@\HLJLn{im}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{{\textasciicircum}}@*)(*@\HLJLp{(}@*)(*@\HLJLn{im}@*)(*@\HLJLoB{*}@*)(*@\HLJLn{\ensuremath{\beta}}@*)(*@\HLJLp{)}@*) (*@\HLJLoB{-}@*) (*@\HLJLnf{exp}@*)(*@\HLJLp{(}@*)(*@\HLJLoB{-}@*)(*@\HLJLni{2}@*)(*@\HLJLn{\ensuremath{\pi}}@*)(*@\HLJLoB{*}@*)(*@\HLJLn{\ensuremath{\beta}}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{*}@*)(*@\HLJLp{(}@*)(*@\HLJLn{x}@*)(*@\HLJLoB{-}@*)(*@\HLJLnfB{0.0}@*)(*@\HLJLn{im}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{{\textasciicircum}}@*)(*@\HLJLp{(}@*)(*@\HLJLn{im}@*)(*@\HLJLoB{*}@*)(*@\HLJLn{\ensuremath{\beta}}@*)(*@\HLJLp{)}@*) \end{lstlisting} \begin{lstlisting} -3.3881317890172014e-21 + 1.0842021724855044e-19im \end{lstlisting} We actually have bounded (oscillatory) growth near zero since \[ |\E^{\I \beta \log z}| = |\E^{\I \beta \log |z|} \E^{-\beta \arg z}| = \E^{-\beta \arg z} \] Thus if we write $c = r \E^{\I \theta}$ for $0 < \theta < 2 \pi$ and define $\alpha = -{\theta \over 2 \pi} + \I{\log r \over 2 \pi}$ we can write the solution to 4.1 as \[ \kappa(z) = (z-1)^{-\alpha} (z+1)^{\alpha-1} \] The same arguments as before then proceed. and the solution to 4.3 is \[ \phi(z) = \kappa(z) \CC\br[{f \over \kappa_+}](z)+ C \kappa(z) \] \begin{lstlisting} (*@\HLJLn{\ensuremath{\theta}}@*) (*@\HLJLoB{=}@*)(*@\HLJLnfB{2.3}@*) (*@\HLJLn{\ensuremath{\alpha}}@*) (*@\HLJLoB{=}@*) (*@\HLJLoB{-}@*)(*@\HLJLn{\ensuremath{\theta}}@*)(*@\HLJLoB{/}@*)(*@\HLJLp{(}@*)(*@\HLJLni{2}@*)(*@\HLJLn{\ensuremath{\pi}}@*)(*@\HLJLp{)}@*) (*@\HLJLn{\ensuremath{\kappa}}@*) (*@\HLJLoB{=}@*) (*@\HLJLn{z}@*) (*@\HLJLoB{->}@*) (*@\HLJLp{(}@*)(*@\HLJLn{z}@*)(*@\HLJLoB{-}@*)(*@\HLJLni{1}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{{\textasciicircum}}@*)(*@\HLJLp{(}@*)(*@\HLJLoB{-}@*)(*@\HLJLn{\ensuremath{\alpha}}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{*}@*)(*@\HLJLp{(}@*)(*@\HLJLn{z}@*)(*@\HLJLoB{+}@*)(*@\HLJLni{1}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{{\textasciicircum}}@*)(*@\HLJLp{(}@*)(*@\HLJLn{\ensuremath{\alpha}}@*)(*@\HLJLoB{-}@*)(*@\HLJLni{1}@*)(*@\HLJLp{)}@*) (*@\HLJLnf{\ensuremath{\kappa}}@*)(*@\HLJLp{(}@*)(*@\HLJLnfB{0.1}@*)(*@\HLJLoB{+}@*)(*@\HLJLnfB{0.0}@*)(*@\HLJLn{im}@*)(*@\HLJLp{)}@*) (*@\HLJLoB{-}@*) (*@\HLJLnf{exp}@*)(*@\HLJLp{(}@*)(*@\HLJLn{im}@*)(*@\HLJLoB{*}@*)(*@\HLJLn{\ensuremath{\theta}}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{*}@*)(*@\HLJLnf{\ensuremath{\kappa}}@*)(*@\HLJLp{(}@*)(*@\HLJLnfB{0.1}@*)(*@\HLJLoB{-}@*)(*@\HLJLnfB{0.0}@*)(*@\HLJLn{im}@*)(*@\HLJLp{)}@*) \end{lstlisting} \begin{lstlisting} 0.0 + 1.1102230246251565e-16im \end{lstlisting} \begin{lstlisting} (*@\HLJLn{r}@*) (*@\HLJLoB{=}@*) (*@\HLJLnfB{2.4}@*) (*@\HLJLn{\ensuremath{\theta}}@*) (*@\HLJLoB{=}@*) (*@\HLJLnfB{2.1}@*) (*@\HLJLn{c}@*) (*@\HLJLoB{=}@*) (*@\HLJLn{r}@*)(*@\HLJLoB{*}@*)(*@\HLJLnf{exp}@*)(*@\HLJLp{(}@*)(*@\HLJLn{im}@*)(*@\HLJLoB{*}@*)(*@\HLJLn{\ensuremath{\theta}}@*)(*@\HLJLp{)}@*) (*@\HLJLn{\ensuremath{\alpha}}@*) (*@\HLJLoB{=}@*) (*@\HLJLoB{-}@*)(*@\HLJLn{\ensuremath{\theta}}@*)(*@\HLJLoB{/}@*)(*@\HLJLp{(}@*)(*@\HLJLni{2}@*)(*@\HLJLn{\ensuremath{\pi}}@*)(*@\HLJLp{)}@*) (*@\HLJLoB{+}@*) (*@\HLJLn{im}@*)(*@\HLJLoB{*}@*)(*@\HLJLnf{log}@*)(*@\HLJLp{(}@*)(*@\HLJLn{r}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{/}@*)(*@\HLJLp{(}@*)(*@\HLJLni{2}@*)(*@\HLJLn{\ensuremath{\pi}}@*)(*@\HLJLp{)}@*) (*@\HLJLn{\ensuremath{\kappa}}@*) (*@\HLJLoB{=}@*) (*@\HLJLn{z}@*) (*@\HLJLoB{->}@*) (*@\HLJLp{(}@*)(*@\HLJLn{z}@*)(*@\HLJLoB{-}@*)(*@\HLJLni{1}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{{\textasciicircum}}@*)(*@\HLJLp{(}@*)(*@\HLJLoB{-}@*)(*@\HLJLn{\ensuremath{\alpha}}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{*}@*)(*@\HLJLp{(}@*)(*@\HLJLn{z}@*)(*@\HLJLoB{+}@*)(*@\HLJLni{1}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{{\textasciicircum}}@*)(*@\HLJLp{(}@*)(*@\HLJLn{\ensuremath{\alpha}}@*)(*@\HLJLoB{-}@*)(*@\HLJLni{1}@*)(*@\HLJLp{)}@*) (*@\HLJLnf{\ensuremath{\kappa}}@*)(*@\HLJLp{(}@*)(*@\HLJLnfB{0.1}@*)(*@\HLJLoB{+}@*)(*@\HLJLnfB{0.0}@*)(*@\HLJLn{im}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{-}@*)(*@\HLJLn{c}@*)(*@\HLJLoB{*}@*)(*@\HLJLnf{\ensuremath{\kappa}}@*)(*@\HLJLp{(}@*)(*@\HLJLnfB{0.1}@*)(*@\HLJLoB{-}@*)(*@\HLJLnfB{0.0}@*)(*@\HLJLn{im}@*)(*@\HLJLp{)}@*) \end{lstlisting} \begin{lstlisting} 2.220446049250313e-16 + 2.220446049250313e-16im \end{lstlisting} \subsection{Problem 5.1} \begin{itemize} \item[1. ] It is a product of functions analytic off $(-\infty,1]$ hence is analytic off $(-\infty,1]$, and we just have to check that it has no jump on $(-\infty,-1)$ and $(-a,a)$. This follows via, for $x < -1$: \end{itemize} \begin{align*} \kappa_+(x) = {1 \over \I^4 \sqrt{1-x}\sqrt{-1-x}\sqrt{a-x}\sqrt{-a-x}} = {1 \over (-\I)^4 \sqrt{1-x}\sqrt{-1-x}\sqrt{a-x}\sqrt{-a-x}} = \kappa_-(x) \end{align*} and for $-a < x < a$ we have \[ \kappa_+(x) = {1 \over \I^2 \sqrt{1-x}\sqrt{x+1}\sqrt{a-x}\sqrt{x+a}} = {1 \over (-\I)^2 \sqrt{1-x}\sqrt{1+x}\sqrt{a-x}\sqrt{-a-x}} = \kappa_-(x) \] \begin{itemize} \item[2. ] This follows via the usual arguments: for $a < x < 1$ we have: \end{itemize} \[ \kappa_+(x) = {1 \over \I \sqrt{1-x}\sqrt{x+1}\sqrt{x-a}\sqrt{x+a}} = -\kappa_-(x) \] and for $-1 < x < -a$ we have \[ \kappa_+(x) = {1 \over \I^3 \sqrt{1-x}\sqrt{x+1}\sqrt{x-a}\sqrt{x+a}} = -\kappa_-(x) \] \begin{itemize} \item[3. ] This has at most square singularitie4s which are weaker than poles \item[4. ] \[ \kappa(z) = {1 \over z^2 \sqrt{1-1/z}\sqrt{1-a/z} \sqrt{1+a/z} \sqrt{1+1/z}} \sim {1 \over z^2} \rightarrow 0 \] . \end{itemize} \subsection{Problem 5.2} Ah, this is a trick question! Note that $z \kappa(z) \sim z^{-1} = O(z)$ and satisfies all the other properties. Thus consider any other solution $\tilde \kappa(z)$ and write \[ r(z) = {\tilde \kappa(z) \over \kappa(z) } \] This has trivial jumps and hence is entire: for example, on $(a,1)$ we have \[ r_+(x) = {\tilde \kappa_+(x) \over \kappa_+(x) } = {-\tilde \kappa_-(x) \over -\kappa_-(x) } = r_-(x) \] But since $\kappa \sim O(z^{-2})$ we only know that $\kappa$ has at most $O(z)$ growth, hence it can be any first degree polynomial. Therefore, the space of all solutions is in fact two-dimensional: $\psi(z) = (A + Bz) \kappa(z)$. \subsection{Problem 5.3} Here we mimick the usual solution techniques and propose: \[ \phi(z) = \kappa(z) \CC\br[{f \over \kappa_+}](z) + (A+Bz) \kappa(z) \] A quick check confirms it has the right jumps: \begin{align*} \phi_+(x) &= \kappa_+(x) \CC_+\br[{f \over \kappa_+}](x) + (A+Bx) \kappa_+(x)\\ & =\kappa_+(x) \left({f(x) \over \kappa_+(x)} + \CC_-\br[{f \over \kappa_+}](x)\right) - (A+Bx) \kappa_-(x) = -\phi_-(x) + f(x) \end{align*} \newpage \subsection{Problem 6.1} Let's first do a plot and histogram. Here we see the right scaling is $N^{1/4}$, using a simplified model without the second derivative (we expect this to go to the same distribution): \begin{lstlisting} (*@\HLJLk{using}@*) (*@\HLJLn{DifferentialEquations}@*) (*@\HLJLn{V}@*) (*@\HLJLoB{=}@*) (*@\HLJLn{x}@*) (*@\HLJLoB{->}@*) (*@\HLJLn{x}@*)(*@\HLJLoB{{\textasciicircum}}@*)(*@\HLJLni{4}@*) (*@\HLJLn{Vp}@*) (*@\HLJLoB{=}@*) (*@\HLJLn{x}@*) (*@\HLJLoB{->}@*) (*@\HLJLni{4}@*)(*@\HLJLn{x}@*)(*@\HLJLoB{{\textasciicircum}}@*)(*@\HLJLni{3}@*) (*@\HLJLn{N}@*) (*@\HLJLoB{=}@*) (*@\HLJLni{50}@*) (*@\HLJLn{\ensuremath{\lambda}{\_}0}@*) (*@\HLJLoB{=}@*) (*@\HLJLnf{randn}@*)(*@\HLJLp{(}@*)(*@\HLJLn{N}@*)(*@\HLJLp{)}@*) (*@\HLJLcs{{\#}}@*) (*@\HLJLcs{initial}@*) (*@\HLJLcs{location}@*) (*@\HLJLn{prob}@*) (*@\HLJLoB{=}@*) (*@\HLJLnf{ODEProblem}@*)(*@\HLJLp{(}@*)(*@\HLJLk{function}@*)(*@\HLJLp{(}@*)(*@\HLJLn{\ensuremath{\lambda}}@*)(*@\HLJLp{,}@*)(*@\HLJLn{{\_}}@*)(*@\HLJLp{,}@*)(*@\HLJLn{t}@*)(*@\HLJLp{)}@*) (*@\HLJLp{[}@*)(*@\HLJLnf{sum}@*)(*@\HLJLp{(}@*)(*@\HLJLni{1}@*) (*@\HLJLoB{./}@*) (*@\HLJLp{(}@*)(*@\HLJLn{\ensuremath{\lambda}}@*)(*@\HLJLp{[}@*)(*@\HLJLn{k}@*)(*@\HLJLp{]}@*) (*@\HLJLoB{.-}@*) (*@\HLJLn{\ensuremath{\lambda}}@*)(*@\HLJLp{[[}@*)(*@\HLJLni{1}@*)(*@\HLJLoB{:}@*)(*@\HLJLn{k}@*)(*@\HLJLoB{-}@*)(*@\HLJLni{1}@*)(*@\HLJLp{;}@*)(*@\HLJLn{k}@*)(*@\HLJLoB{+}@*)(*@\HLJLni{1}@*)(*@\HLJLoB{:}@*)(*@\HLJLk{end}@*)(*@\HLJLp{]]))}@*) (*@\HLJLoB{-}@*) (*@\HLJLnf{Vp}@*)(*@\HLJLp{(}@*)(*@\HLJLn{\ensuremath{\lambda}}@*)(*@\HLJLp{[}@*)(*@\HLJLn{k}@*)(*@\HLJLp{])}@*) (*@\HLJLk{for}@*) (*@\HLJLn{k}@*)(*@\HLJLoB{=}@*)(*@\HLJLni{1}@*)(*@\HLJLoB{:}@*)(*@\HLJLn{N}@*)(*@\HLJLp{]}@*) (*@\HLJLk{end}@*)(*@\HLJLp{,}@*) (*@\HLJLn{\ensuremath{\lambda}{\_}0}@*)(*@\HLJLp{,}@*) (*@\HLJLp{(}@*)(*@\HLJLnfB{0.0}@*)(*@\HLJLp{,}@*) (*@\HLJLnfB{5.0}@*)(*@\HLJLp{))}@*) (*@\HLJLn{\ensuremath{\lambda}}@*) (*@\HLJLoB{=}@*) (*@\HLJLnf{solve}@*)(*@\HLJLp{(}@*)(*@\HLJLn{prob}@*)(*@\HLJLp{;}@*) (*@\HLJLn{reltol}@*)(*@\HLJLoB{=}@*)(*@\HLJLnfB{1E-6}@*)(*@\HLJLp{);}@*) (*@\HLJLn{t}@*) (*@\HLJLoB{=}@*) (*@\HLJLnfB{5.0}@*) (*@\HLJLnf{scatter}@*)(*@\HLJLp{(}@*)(*@\HLJLnf{\ensuremath{\lambda}}@*)(*@\HLJLp{(}@*)(*@\HLJLn{t}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{/}@*)(*@\HLJLn{N}@*)(*@\HLJLoB{{\textasciicircum}}@*)(*@\HLJLp{(}@*)(*@\HLJLni{1}@*)(*@\HLJLoB{/}@*)(*@\HLJLni{4}@*)(*@\HLJLp{)}@*) (*@\HLJLp{,}@*)(*@\HLJLnf{zeros}@*)(*@\HLJLp{(}@*)(*@\HLJLn{N}@*)(*@\HLJLp{);}@*) (*@\HLJLn{label}@*)(*@\HLJLoB{=}@*)(*@\HLJLs{"{}charges"{}}@*)(*@\HLJLp{,}@*) (*@\HLJLn{xlims}@*)(*@\HLJLoB{=}@*)(*@\HLJLp{(}@*)(*@\HLJLoB{-}@*)(*@\HLJLni{2}@*)(*@\HLJLp{,}@*)(*@\HLJLni{2}@*)(*@\HLJLp{),}@*) (*@\HLJLn{title}@*)(*@\HLJLoB{=}@*)(*@\HLJLs{"{}t}@*) (*@\HLJLs{=}@*) (*@\HLJLsi{{\$}t}@*)(*@\HLJLs{"{}}@*)(*@\HLJLp{)}@*) \end{lstlisting} \includegraphics[width=\linewidth]{C:/Users/mfaso/OneDrive/Documents/GitHub/M3M6AppliedComplexAnalysis/output/figures/Solutions3_34_1.pdf} The limiting distribution has the following form: \begin{lstlisting} (*@\HLJLnf{histogram}@*)(*@\HLJLp{(}@*)(*@\HLJLnf{\ensuremath{\lambda}}@*)(*@\HLJLp{(}@*)(*@\HLJLn{t}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{/}@*)(*@\HLJLn{N}@*)(*@\HLJLoB{{\textasciicircum}}@*)(*@\HLJLp{(}@*)(*@\HLJLni{1}@*)(*@\HLJLoB{/}@*)(*@\HLJLni{4}@*)(*@\HLJLp{);}@*) (*@\HLJLn{nbins}@*)(*@\HLJLoB{=}@*)(*@\HLJLni{30}@*)(*@\HLJLp{,}@*) (*@\HLJLn{normalize}@*)(*@\HLJLoB{=}@*)(*@\HLJLkc{true}@*)(*@\HLJLp{,}@*) (*@\HLJLn{label}@*)(*@\HLJLoB{=}@*)(*@\HLJLs{"{}histogram}@*) (*@\HLJLs{of}@*) (*@\HLJLs{charges"{}}@*)(*@\HLJLp{)}@*) \end{lstlisting} \includegraphics[width=\linewidth]{C:/Users/mfaso/OneDrive/Documents/GitHub/M3M6AppliedComplexAnalysis/output/figures/Solutions3_35_1.pdf} We want to solve \[ {\D^2 \lambda_k \over \D t^2} + \gamma {\D \lambda_k \over \D t} = \sum_{j=1 \atop j \neq k}^N {1 \over \lambda_k -\lambda_j} - 4\lambda_k^3 \] Rescale via $\mu_k = {\lambda_k \over N^{1/4}}$ gives \[ 0 = N^{1/4} \br[{\D^2 \lambda_k \over \D t^2} + \gamma {\D \lambda_k \over \D t}] = N^{-1/4} \sum_{j=1 \atop j \neq k}^N {1 \over \mu_k -\mu_j} - 4 N^{3/4} \mu_k^3 \] or in other words \[ 0 = N^{-1/2} \br[{\D^2 \lambda_k \over \D t^2} + \gamma {\D \lambda_k \over \D t}] = {1 \over N} \sum_{j=1 \atop j \neq k}^N {1 \over \mu_k -\mu_j} - 4 \mu_k^3 \] We can now formally let $N\rightarrow \infty$ to get our equation \[ \dashint_{-b}^b {w(t) \over x-t} \dt = 4 x^3 \] where I've used symmetry to assume that the interval is symmetric. We want to find $w$ and $b$ so that this equations holds true and $w$ is a bounded probability density: \begin{itemize} \item[1. ] \[ w(x) >0 \] for $-b < x < b$ \item[2. ] \[ \int w(x) \dx = 1 \] \item[3. ] \[ w \] is bounded \end{itemize} \newpage Our equation is equivalent to \[ \HH_{[-b,b]} w(x) = {4 x^3 \over \pi} \] recall the inversion formula \[ u(x) = {-1 \over \sqrt{b^2 - x^2}}\HH \left[{ f(\diamond) \sqrt{b^2-\diamond^2} }\right](x) - {C \over \sqrt{b^2-x^2}} \] In our case $f(x) = {4 x^3 \over \pi}$ and we use \[ \sqrt{z-b}\sqrt{z+b} = z\sqrt{1-b/z}\sqrt{1+b/z} = z - {b^2 \over 2 z} -{b^4 \over 8z^3} + O(z^{-4}) \] to determine \[ 2 \I \CC \left[{ \diamond^3 \sqrt{b^2-\diamond^2} }\right](x) = z^3(\sqrt{z-b}\sqrt{z+b} -z + {b^2 \over 2 z} + {b^4 \over 8z^3}) = z^3\sqrt{z-b}\sqrt{z+b} -z^4 + {b^2z^2 \over 2} + {b^4 \over 8} \] \begin{lstlisting} (*@\HLJLn{b}@*) (*@\HLJLoB{=}@*) (*@\HLJLni{5}@*) (*@\HLJLn{x}@*) (*@\HLJLoB{=}@*) (*@\HLJLnf{Fun}@*)(*@\HLJLp{(}@*)(*@\HLJLoB{-}@*)(*@\HLJLn{b}@*) (*@\HLJLoB{..}@*) (*@\HLJLn{b}@*)(*@\HLJLp{)}@*) (*@\HLJLp{(}@*)(*@\HLJLni{2}@*)(*@\HLJLn{im}@*)(*@\HLJLp{)}@*)(*@\HLJLnf{cauchy}@*)(*@\HLJLp{(}@*)(*@\HLJLn{x}@*)(*@\HLJLoB{{\textasciicircum}}@*)(*@\HLJLni{3}@*)(*@\HLJLoB{*}@*)(*@\HLJLnf{sqrt}@*)(*@\HLJLp{(}@*)(*@\HLJLn{b}@*)(*@\HLJLoB{{\textasciicircum}}@*)(*@\HLJLni{2}@*)(*@\HLJLoB{-}@*)(*@\HLJLn{x}@*)(*@\HLJLoB{{\textasciicircum}}@*)(*@\HLJLni{2}@*)(*@\HLJLp{),}@*)(*@\HLJLn{z}@*)(*@\HLJLp{)}@*) \end{lstlisting} \begin{lstlisting} 71.6687198577313 + 40.090510492433154im \end{lstlisting} Therefore, \begin{align*} u(x) = {4\I \over \pi \sqrt{b^2 - x^2}}(\CC^+ + \CC^-) \left[{ \diamond^3 \sqrt{b^2-\diamond^2} }\right](x) - {C \over \sqrt{b^2-x^2}} \\ {4 \over \pi \sqrt{b^2 - x^2}}(-x^4+{b^2 x^2 \over 2} + {b^4 \over 8})- {C \over \sqrt{b^2-x^2}} \end{align*} We choose $C$ so this is bounded, in particular, we get get the solution \[ u(x) = {4 \over \pi \sqrt{b^2 - x^2}}(-x^4+{b^2 x^2 \over 2} + {b^4 \over 2}) \] \newpage \begin{lstlisting} (*@\HLJLn{u}@*) (*@\HLJLoB{=}@*) (*@\HLJLni{4}@*)(*@\HLJLoB{/}@*)(*@\HLJLp{(}@*)(*@\HLJLn{\ensuremath{\pi}}@*)(*@\HLJLoB{*}@*)(*@\HLJLnf{sqrt}@*)(*@\HLJLp{(}@*)(*@\HLJLn{b}@*)(*@\HLJLoB{{\textasciicircum}}@*)(*@\HLJLni{2}@*)(*@\HLJLoB{-}@*)(*@\HLJLn{x}@*)(*@\HLJLoB{{\textasciicircum}}@*)(*@\HLJLni{2}@*)(*@\HLJLp{))}@*)(*@\HLJLoB{*}@*)(*@\HLJLp{(}@*)(*@\HLJLoB{-}@*)(*@\HLJLn{x}@*)(*@\HLJLoB{{\textasciicircum}}@*)(*@\HLJLni{4}@*) (*@\HLJLoB{+}@*) (*@\HLJLn{b}@*)(*@\HLJLoB{{\textasciicircum}}@*)(*@\HLJLni{2}@*)(*@\HLJLoB{*}@*)(*@\HLJLn{x}@*)(*@\HLJLoB{{\textasciicircum}}@*)(*@\HLJLni{2}@*)(*@\HLJLoB{/}@*)(*@\HLJLni{2}@*) (*@\HLJLoB{+}@*) (*@\HLJLn{b}@*)(*@\HLJLoB{{\textasciicircum}}@*)(*@\HLJLni{4}@*)(*@\HLJLoB{/}@*)(*@\HLJLni{2}@*)(*@\HLJLp{)}@*) (*@\HLJLnf{H}@*)(*@\HLJLp{(}@*)(*@\HLJLn{u}@*)(*@\HLJLp{,}@*) (*@\HLJLnfB{0.1}@*)(*@\HLJLp{),}@*)(*@\HLJLni{4}@*)(*@\HLJLoB{*}@*)(*@\HLJLnfB{0.1}@*)(*@\HLJLoB{{\textasciicircum}}@*)(*@\HLJLni{3}@*)(*@\HLJLoB{/}@*)(*@\HLJLn{\ensuremath{\pi}}@*) \end{lstlisting} \begin{lstlisting} (0.0012732395447351292, 0.001273239544735163) \end{lstlisting} At least it looks right, we just need to get the right b: \begin{lstlisting} (*@\HLJLnf{plot}@*)(*@\HLJLp{(}@*)(*@\HLJLn{u}@*)(*@\HLJLp{;}@*) (*@\HLJLn{label}@*) (*@\HLJLoB{=}@*) (*@\HLJLs{"{}b}@*) (*@\HLJLs{=}@*) (*@\HLJLsi{{\$}b}@*)(*@\HLJLs{"{}}@*)(*@\HLJLp{)}@*) \end{lstlisting} \includegraphics[width=\linewidth]{C:/Users/mfaso/OneDrive/Documents/GitHub/M3M6AppliedComplexAnalysis/output/figures/Solutions3_38_1.pdf} We want to choose $b$ now so that this integrates to $1$. For example, this choice of $b$ is horrible: \begin{lstlisting} (*@\HLJLnf{sum}@*)(*@\HLJLp{(}@*)(*@\HLJLn{u}@*)(*@\HLJLp{)}@*) \end{lstlisting} \begin{lstlisting} 937.5 \end{lstlisting} There's a nice trick: If $-2\pi \I \CC u(z) \sim {1 \over z}$ then $\int_{-b}^b u(x) \dx = 1$. We know since \[ {1 \over \sqrt{1+z}} = 1 - {z \over 2} + {3z^2 \over 8} - {5z^3 \over 16} + O(z^4) \] \begin{align*} {-z^4 + {b^2z^2 \over 2} + {b^4 \over 2} \over \sqrt{z-b}\sqrt{z+b}} &= {-z^3 + {b^2z \over 2} + {b^4 \over 2 z} \over \sqrt{1-b/z}\sqrt{1+b/z}} \\ &= (-z^3 + {b^2z \over 2} )(1 + {b \over 2 z} + {3 b^2 \over 8 z^2} + {5 b^3 \over 16z^3} )(1 - {b \over 2 z} + {3 b^2 \over 8 z^2} - {5 b^3 \over 16z^3}) + O(z^{-1}) \\ &=-z^3 + \pr({b^2 \over 2} +{b^2 \over 4} + {b^2 \over 2} - {3 b^2 \over 8} -{3 b^2 \over 8} ) z +O(z^{-1})\\ &= -z^3 + O(z^{-1}) \end{align*} Thus we know \[ \CC u(z) = {2\I \over \pi} z^3 +{2 \I \over \pi} {-z^4 + {b^2z^2 \over 2} + {b^4 \over 2} \over \sqrt{z-b}\sqrt{z+b}} \] \begin{lstlisting} (*@\HLJLnf{cauchy}@*)(*@\HLJLp{(}@*)(*@\HLJLn{u}@*)(*@\HLJLp{,}@*) (*@\HLJLn{z}@*)(*@\HLJLp{)}@*) (*@\HLJLn{z}@*) (*@\HLJLoB{=}@*)(*@\HLJLnfB{100.0}@*)(*@\HLJLn{im}@*)(*@\HLJLp{;}@*) (*@\HLJLni{2}@*)(*@\HLJLn{im}@*)(*@\HLJLoB{/}@*)(*@\HLJLn{\ensuremath{\pi}}@*)(*@\HLJLoB{*}@*)(*@\HLJLn{z}@*)(*@\HLJLoB{{\textasciicircum}}@*)(*@\HLJLni{3}@*) (*@\HLJLoB{+}@*) (*@\HLJLni{2}@*)(*@\HLJLn{im}@*)(*@\HLJLoB{/}@*)(*@\HLJLn{\ensuremath{\pi}}@*)(*@\HLJLoB{*}@*)(*@\HLJLp{(}@*)(*@\HLJLoB{-}@*)(*@\HLJLn{z}@*)(*@\HLJLoB{{\textasciicircum}}@*)(*@\HLJLni{4}@*) (*@\HLJLoB{+}@*) (*@\HLJLn{b}@*)(*@\HLJLoB{{\textasciicircum}}@*)(*@\HLJLni{2}@*)(*@\HLJLoB{*}@*)(*@\HLJLn{z}@*)(*@\HLJLoB{{\textasciicircum}}@*)(*@\HLJLni{2}@*)(*@\HLJLoB{/}@*)(*@\HLJLni{2}@*) (*@\HLJLoB{+}@*)(*@\HLJLn{b}@*)(*@\HLJLoB{{\textasciicircum}}@*)(*@\HLJLni{4}@*)(*@\HLJLoB{/}@*)(*@\HLJLni{2}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{/}@*)(*@\HLJLp{(}@*)(*@\HLJLnf{sqrt}@*)(*@\HLJLp{(}@*)(*@\HLJLn{z}@*)(*@\HLJLoB{-}@*)(*@\HLJLn{b}@*)(*@\HLJLp{)}@*)(*@\HLJLnf{sqrt}@*)(*@\HLJLp{(}@*)(*@\HLJLn{z}@*)(*@\HLJLoB{+}@*)(*@\HLJLn{b}@*)(*@\HLJLp{))}@*) \end{lstlisting} \begin{lstlisting} 1.4908359390683472 - 0.0im \end{lstlisting} taking this one term further we find \[ {-z^4 + {b^2z^2 \over 2} + {b^4 \over 2} \over \sqrt{z-b}\sqrt{z+b}} = -z^3 +{3 b^4 \over 8 z} + O(z^{-2}) \] Hence we want to choose $b$ so that \[ -2\I\pi \CC u(z) = {3 b^4 \over 2 z} \sim {1 \over z} \] in other words, $b = ({2 \over 3})^{1/4}$ \begin{lstlisting} (*@\HLJLn{b}@*) (*@\HLJLoB{=}@*) (*@\HLJLp{(}@*)(*@\HLJLni{2}@*)(*@\HLJLoB{/}@*)(*@\HLJLni{3}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{{\textasciicircum}}@*)(*@\HLJLp{(}@*)(*@\HLJLni{1}@*)(*@\HLJLoB{/}@*)(*@\HLJLni{4}@*)(*@\HLJLp{)}@*) (*@\HLJLn{x}@*) (*@\HLJLoB{=}@*) (*@\HLJLnf{Fun}@*)(*@\HLJLp{(}@*)(*@\HLJLoB{-}@*)(*@\HLJLn{b}@*) (*@\HLJLoB{..}@*) (*@\HLJLn{b}@*)(*@\HLJLp{)}@*) (*@\HLJLn{u}@*) (*@\HLJLoB{=}@*) (*@\HLJLni{4}@*)(*@\HLJLoB{/}@*)(*@\HLJLp{(}@*)(*@\HLJLn{\ensuremath{\pi}}@*)(*@\HLJLoB{*}@*)(*@\HLJLnf{sqrt}@*)(*@\HLJLp{(}@*)(*@\HLJLn{b}@*)(*@\HLJLoB{{\textasciicircum}}@*)(*@\HLJLni{2}@*)(*@\HLJLoB{-}@*)(*@\HLJLn{x}@*)(*@\HLJLoB{{\textasciicircum}}@*)(*@\HLJLni{2}@*)(*@\HLJLp{))}@*)(*@\HLJLoB{*}@*)(*@\HLJLp{(}@*)(*@\HLJLoB{-}@*)(*@\HLJLn{x}@*)(*@\HLJLoB{{\textasciicircum}}@*)(*@\HLJLni{4}@*) (*@\HLJLoB{+}@*) (*@\HLJLn{b}@*)(*@\HLJLoB{{\textasciicircum}}@*)(*@\HLJLni{2}@*)(*@\HLJLoB{*}@*)(*@\HLJLn{x}@*)(*@\HLJLoB{{\textasciicircum}}@*)(*@\HLJLni{2}@*)(*@\HLJLoB{/}@*)(*@\HLJLni{2}@*) (*@\HLJLoB{+}@*) (*@\HLJLn{b}@*)(*@\HLJLoB{{\textasciicircum}}@*)(*@\HLJLni{4}@*)(*@\HLJLoB{/}@*)(*@\HLJLni{2}@*)(*@\HLJLp{)}@*) (*@\HLJLnf{sum}@*)(*@\HLJLp{(}@*)(*@\HLJLn{u}@*)(*@\HLJLp{)}@*) \end{lstlisting} \begin{lstlisting} 0.9999999999999997 \end{lstlisting} And it worked! \begin{lstlisting} (*@\HLJLnf{histogram}@*)(*@\HLJLp{(}@*)(*@\HLJLnf{\ensuremath{\lambda}}@*)(*@\HLJLp{(}@*)(*@\HLJLnfB{5.0}@*)(*@\HLJLp{)}@*)(*@\HLJLoB{/}@*)(*@\HLJLn{N}@*)(*@\HLJLoB{{\textasciicircum}}@*)(*@\HLJLp{(}@*)(*@\HLJLni{1}@*)(*@\HLJLoB{/}@*)(*@\HLJLni{4}@*)(*@\HLJLp{);}@*) (*@\HLJLn{nbins}@*)(*@\HLJLoB{=}@*)(*@\HLJLni{25}@*)(*@\HLJLp{,}@*) (*@\HLJLn{normalize}@*)(*@\HLJLoB{=}@*)(*@\HLJLkc{true}@*)(*@\HLJLp{,}@*) (*@\HLJLn{label}@*)(*@\HLJLoB{=}@*)(*@\HLJLs{"{}histogram}@*) (*@\HLJLs{of}@*) (*@\HLJLs{charges"{}}@*)(*@\HLJLp{)}@*) (*@\HLJLnf{plot!}@*)(*@\HLJLp{(}@*)(*@\HLJLn{u}@*)(*@\HLJLp{;}@*) (*@\HLJLn{label}@*)(*@\HLJLoB{=}@*)(*@\HLJLs{"{}u"{}}@*)(*@\HLJLp{,}@*)(*@\HLJLn{xlims}@*)(*@\HLJLoB{=}@*)(*@\HLJLp{(}@*)(*@\HLJLoB{-}@*)(*@\HLJLni{2}@*)(*@\HLJLp{,}@*)(*@\HLJLni{2}@*)(*@\HLJLp{))}@*) \end{lstlisting} \includegraphics[width=\linewidth]{C:/Users/mfaso/OneDrive/Documents/GitHub/M3M6AppliedComplexAnalysis/output/figures/Solutions3_42_1.pdf} } \end{document}
%% Copyright (C) 2009-2011, Gostai S.A.S. %% %% This software is provided "as is" without warranty of any kind, %% either expressed or implied, including but not limited to the %% implied warranties of fitness for a particular purpose. %% %% See the LICENSE file for more information. \section{Math} This object is meant to play the role of a name-space in which the mathematical functions are defined with a more conventional notation. Indeed, in an object-oriented language, writing \lstinline|pi.cos| makes perfect sense, yet \lstinline|cos(pi)| is more usual. Math is a package, so you can use \begin{urbiscript} import Math.*; \end{urbiscript} to make its Slots visible. \subsection{Prototypes} \begin{refObjects} \item[Singleton] \end{refObjects} \subsection{Construction} Since it is a \refObject{Singleton}, you are not expected to build other instances. \subsection{Slots} \begin{urbiscriptapi} \item[abs](<float>)% Bounce to \refSlot[Float]{abs}. \begin{urbiassert} Math.abs(1) == Math.abs(-1) == 1; Math.abs(0) == 0; Math.abs(3.5) == Math.abs(-3.5) == 3.5; \end{urbiassert} \item[acos](<float>)% Bounce to \refSlot[Float]{acos}. \begin{urbiassert} Math.acos(0) == Float.pi/2; Math.acos(1) == 0; \end{urbiassert} \item[asin](<float>)% Bounce to \refSlot[Float]{asin}. \begin{urbiassert} Math.asin(0) == 0; \end{urbiassert} \item[atan](<float>)% Bounce to \refSlot[Float]{atan}. \begin{urbiassert} Math.atan(1) ~= pi/4; \end{urbiassert} \item[atan2](<x>, <y>)% Bounce to \lstinline|\var{x}.atan2(\var{y})|. \begin{urbiassert} Math.atan2(2, 2) ~= pi/4; Math.atan2(-2, 2) ~= -pi/4; \end{urbiassert} \item[ceil] Bounce to \refSlot[Float]{ceil}. \begin{urbiassert} Math.ceil(1.4) == Math.ceil(1.5) == Math.ceil(1.6) == Math.ceil(2) == 2; \end{urbiassert} \item[cos](<float>)% Bounce to \refSlot[Float]{cos}. \begin{urbiassert} Math.cos(0) == 1; Math.cos(pi) ~= -1; \end{urbiassert} \item[exp](<float>)% Bounce to \refSlot[Float]{exp}. \begin{urbiassert} Math.exp(1) ~= 2.71828; \end{urbiassert} \item[floor] Bounce to \refSlot[Float]{floor}. \begin{urbiassert} Math.floor(1) == Math.floor(1.4) == Math.floor(1.5) == Math.floor(1.6) == 1; \end{urbiassert} \item[inf] Bounce to \refSlot[Float]{inf}. \item[log](<float>)% Bounce to \refSlot[Float]{log}. \begin{urbiassert} Math.log(1) == 0; \end{urbiassert} \item[max](<arg1>, ...)% Bounce to \lstinline|[\var{arg1}, ...].max|, see \refSlot[List]{max}. \begin{urbiassert} Math.max( 100, 20, 3 ) == 100; Math.max("100", "20", "3") == "3"; \end{urbiassert} \item[min](<arg1>, ...)% Bounce to \lstinline|[\var{arg1}, ...].min|, see \refSlot[List]{min}. \begin{urbiassert} min( 100, 20, 3 ) == 3; min("100", "20", "3") == "100"; \end{urbiassert} \item[nan] Bounce to \refSlot[Float]{nan}. \item[pi] Bounce to \refSlot[Float]{pi}. \item[random](<float>)% Bounce to \refSlot[Float]{random}. \begin{urbiscript} 20.map(function (dummy) { Math.random(5) }); [00000000] [1, 2, 1, 3, 2, 3, 2, 2, 4, 4, 4, 1, 0, 0, 0, 3, 2, 4, 3, 2] \end{urbiscript} \item[round](<float>)% Bounce to \refSlot[Float]{round}. \begin{urbiassert} Math.round(1 ) == Math.round(1.1) == Math.round(1.49) == 1; Math.round(1.5) == Math.round(1.51) == 2; \end{urbiassert} \item[sign](<float>)% Bounce to \refSlot[Float]{sign}. \begin{urbiassert} Math.sign(-2) == -1; Math.sign(0) == 0; Math.sign(2) == 1; \end{urbiassert} \item[sin](<float>)% Bounce to \refSlot[Float]{sin}. \begin{urbiassert} Math.sin(0) == 0; Math.sin(pi) ~= 0; \end{urbiassert} \item[sqr](<float>)% Bounce to \refSlot[Float]{sqr}. \begin{urbiassert} Math.sqr(1.5) == Math.sqr(-1.5) == 2.25; Math.sqr(16) == Math.sqr(-16) == 256; \end{urbiassert} \item[sqrt](<float>)% Bounce to \refSlot[Float]{sqrt}. \begin{urbiassert} Math.sqrt(4) == 2; \end{urbiassert} \item[srandom](<float>)% Bounce to \refSlot[Float]{srandom}. \item[tan](<float>)% Bounce to \refSlot[Float]{tan}. \begin{urbiassert} Math.tan(pi/4) ~= 1; \end{urbiassert} \item[trunc](<float>)% Bounce to \refSlot[Float]{trunc}. \begin{urbiassert} Math.trunc(1) == Math.trunc(1.1) == Math.trunc(1.49) == Math.trunc(1.5) == Math.trunc(1.51) == 1; \end{urbiassert} \end{urbiscriptapi} %%% Local Variables: %%% coding: utf-8 %%% mode: latex %%% TeX-master: "../urbi-sdk" %%% ispell-dictionary: "american" %%% ispell-personal-dictionary: "../urbi.dict" %%% fill-column: 76 %%% End:
%% thesis.tex 2014/04/11 % % Based on sample files of unknown authorship. % % The Current Maintainer of this work is Paul Vojta. \documentclass{ucbthesis} \usepackage{biblatex} \usepackage{rotating} % provides sidewaystable and sidewaysfigure \usepackage{listings} \usepackage{amsmath,amssymb} \usepackage{amsthm} \usepackage{amsfonts} \usepackage{mathtools} % % To compile this file, run "latex thesis", then "biber thesis" % (or "bibtex thesis", if the output from latex asks for that instead), % and then "latex thesis" (without the quotes in each case). % Double spacing, if you want it. Do not use for the final copy. % \def\dsp{\def\baselinestretch{2.0}\large\normalsize} % \dsp % If the Grad. Division insists that the first paragraph of a section % be indented (like the others), then include this line: % \usepackage{indentfirst} \addtolength{\abovecaptionskip}{\baselineskip} \newtheorem*{remark}{Remark} \newtheorem{theorem}{Theorem}[section] \newtheorem{corollary}{Corollary}[theorem] \newtheorem{lemma}[theorem]{Lemma} \newtheorem{definition}{Definition} \newtheorem{prop}{Proposition} \DeclareMathOperator*{\calX}{\mathcal{X}} \DeclareMathOperator*{\calY}{\mathcal{Y}} \newcommand{\ovl}{\overline} \newcommand{\E}{\mathrm{E}} \newcommand{\Var}{\mathrm{Var}} \newcommand{\Cov}{\mathrm{Cov}} \newcommand{\Prob}{\mathrm{P}} \newcommand{\R}{\mathbb{R}} \newcommand{\C}{\mathbb{C}} % complex numbers \newcommand{\eps}{\varepsilon} % epsilon %\newcommand{\c}{\expandafter\mathcal} % calligraphic \DeclarePairedDelimiter\paren{(}{)} % (parentheses) \DeclarePairedDelimiter\ang{\langle}{\rangle} % <angle brackets> \DeclarePairedDelimiter\abs{\lvert}{\rvert} % |absolute value| \DeclarePairedDelimiter\norm{\lVert}{\rVert} % ||norm|| \DeclarePairedDelimiter\bkt{[}{]} % [brackets] \DeclarePairedDelimiter\set{\{}{\}} %\addbibresource{references.bib} \bibliography{references} \hyphenation{mar-gin-al-ia} \hyphenation{bra-va-do} \begin{document} % Declarations for Front Matter \title{Analyses of Domain Adaptation using Optimal Transport} \author{Yannik Pitcan} \degreesemester{Spring} \degreeyear{2020} \degree{Doctor of Philosophy} \chair{Professor Peter Bartlett} \othermembers{Professor Steve Evans \\ Assistant Professor Avi Feller} % For a co-chair who is subordinate to the \chair listed above % \cochair{Professor Benedict Francis Pope} % For two co-chairs of equal standing (do not use \chair with this one) % \cochairs{Professor Richard Francis Sony}{Professor Benedict Francis Pope} \numberofmembers{3} % Previous degrees are no longer to be listed on the title page. % \prevdegrees{B.A. (University of Northern South Dakota at Hoople) 1978 \\ % M.S. (Ed's School of Quantum Mechanics and Muffler Repair) 1989} \field{Statistics} % Designated Emphasis -- this is optional, and rare % \emphasis{Colloidal Telemetry} % This is optional, and rare % \jointinstitution{University of Western Maryland} % This is optional (default is Berkeley) % \campus{Berkeley} % For a masters thesis, replace the above \documentclass line with % \documentclass[masters]{ucbthesis} % This affects the title and approval pages, which by default calls this % document a "dissertation", not a "thesis". \maketitle % Delete (or comment out) the \approvalpage line for the final version. %\approvalpage \copyrightpage \include{abstract} \begin{frontmatter} \begin{dedication} \null\vfil \begin{center} This is dedicated to my parents. \end{center} \vfil\null \end{dedication} % You can delete the \clearpage lines if you don't want these to start on % separate pages. \tableofcontents \clearpage \listoffigures \clearpage \listoftables \begin{acknowledgements} Someone once said "failure is one's own doing, but success takes a village." I forget who said that, but it could not be more apt. There are multiple people in my life to whom I am incredibly appreciative. First and foremost, I would like to thank Dr. Peter Bartlett. He has been an incredible advisor and suggested this topic and several of the key insights. Without him, I do not know where I would be today. I would also like to thank my colleagues Soren Kuenzel and Alexander Tsigler. Both individuals gave me many suggestions and tips that helped immensely. Lastly, I am thankful for my parents, Grace and Clyde Pitcan, for always believing in me. \end{acknowledgements} \end{frontmatter} \pagestyle{headings} % (Optional) \part{First Part} \include{preliminaries(pjd)} \include{chap1(pjd)} \include{chap2(pjd)} \include{chap3(pjd)} \include{chap4(pjd)} \include{chap5(pjd)} \include{chap6(pjd)} \printbibliography % \appendix % \chapter{More Monticello Candidates} \end{document}
\chapter{Seeking Interoperability} \label{ch:interoperability} Having ontological tools for describing scientific workflows makes it possible to consider how workflow management systems might interoperate. This could include executing workflow campaigns that combine and distribute workflows based solely on the descriptions of the workflows themselves. Interoperable workflow management systems would be extremely valuable to the scientific computing community because of the need to solve increasingly interdisciplinary problems, often using highly componentized domain-specific workflow tools while leveraging exotic architectures. This chapter explores various aspects of interoperability, including its important relationship to interchangeability, and how differences in workflows and subworkflows can be identified ontologically and be shared. Finally, as an example of what ontological tools can offer, a new system for exchanging workflows, data, and metadata that is built on ontological principles is discussed in the context of distributed workflow provenance. \section{Interoperability} \baseInclude{pubs/workflows-paper/src/experience-interop} \baseInclude{pubs/workflows-paper/src/interoperability} \subsection{Interoperable Versus Interchangeable} It is important to understand the distinction between interoperable and interchangeable. Interoperable describes systems that work together by exchanging information, and interchangeable describes things that can be substituted exactly for each other. Interchangeable workflows would mean that any workflow management system could interpret the workflow description for any other workflow management system. Interchangeable workflow descriptions would be as easy to swap as components in computers or parts on two cars of the same model. On the other hand, interoperability for workflows would mean that the workflow management systems that execute workflows could exchange information and operate together to ensure complete execution of the workflows. Requiring components to be interchangeable is a stronger constraint on systems than requiring that they be interoperable. The examples of \S \ref{workflow-ont-examples} can be used to illustrate this. Consider the move workflow of \S \ref{move-workflow}. If two systems supported interchangeable workflow descriptions, then both systems would be required to fully execute the original workflows. Interoperable workflow systems would instead only be required to execute the pieces they could - perhaps \#moveAction - while leaving the rest to partnering systems. The conceptual neutron scattering workflow shown in Figure \ref{neutron-workflow} depicts a system of interoperable workflow management systems. This is evident because no one system could be reasonably expected to do all the proposed tasks. Modeling and simulation tools to perform density functional theory calculations are not the same as tools used to capture, reduce, and curate experimental data. (The differences in workflow management tools across these broad domains are discussed extensively in Chapter \ref{ch:introduction}.) Real user workflows that are executed to realize this conceptual workflow link together many different workflow tools, scripts, and packages that translate, shape, convert, and otherwise manipulate input and output data between the steps. Each little piece of software does its part to exchange and transmute the data in such a way that the other pieces can use it, and, therefore, creates an interoperable ecosystem. This chapter explores the lesser of these two, interoperability, because there are immediate use cases for describing workflows in a common way and distributing the execution across multiple systems. These needs exist in science because, as in the previous example, no workflow management system exists that can handle every subject. Many workflow systems exist that cannot be changed but must still be used. On the contrary, interchangeable workflows would require that all the systems be rebuilt to meet ``interchangeability standards,'' which would increase the development burden and thereby decrease the probability of developers supporting it. \subsection{Practical Hangups and Examples} \label{practicality} Practical systems exhibit many properties not found in theoretical systems that limit or prohibit the ability of developers to provide any of the four properties listed previously. This could be as conceptually simple as language differences that impede communication, challenges with backwards compatibility, missing features in standard libraries, or as complex as deep, subtle design differences that are not easily rectified without translation or reimplementation. Theoretically these challenges can all be rectified in a few pages of instructive text. However, an old economic adage applies: ``There ain't no such thing as a free lunch.''\footnote{Physicists quickly recognize this as a concise restatement of the laws of thermodynamics. Arguably, an experimental thermodynamicist would never get bored applying their trade to the study of programmers.} That is, someone must do the work to address these issues in real systems. Consider some of the issues that can be quickly and easily identified between Eclipse ICE versions 2.0 and 3.0. An existing system, such as Eclipse ICE 2.0, likely has a large number of features, requirements, bug fixes, and ---being completely honest--- ``hacks'' that were necessary to achieve desired functionality. These could be very obvious, such as the fact that Eclipse ICE 2.0 does not use the Resource Description Framework (RDF) whereas version 3.0 does. Several examples of these types of problems are discussed next to illustrate the nature of compatibility issues between systems, including systems developed by the same authors. \subsubsection{Changes in Data Structure Design} \label{ice-data} ICE 3.0 using RDF to describe its data structures is one example of a difference between it and a legacy system such as ICE 2.0. At a design level, this means that ICE 3.0 has data structures that are described completely declaratively and ontologically in RDF, the RDF Schema languages (RDFS), or the Web Ontology Language (OWL). The definitions of the data structures are defined in OWL, which is itself defined in RDF, and instances of these data structures are defined in RDF as well. The ontology exists in one OWL-RDF file, and the instances exist in their own files that import the base ontology. ICE 3.0 not only has different data structures but also uses uses a third-party library, Apache Jena, to implement these data structures and provide useful services, such as mapping to HTTP/HTTPS servers or reading and writing to disks. ICE 2.0 used a custom implementation of its data structures, which were originally transcoded from UML to Java and updated thereafter by hand. Other differences are far more subtle and demanding in their detail. Data structures in ICE 2.0 manage their own notifications. Observers can \textit{register} as listeners to a data structure in ICE 2.0, and that data structure will notify the observer when it changes. This is a very low-level implementation of the observer pattern that was designed to (i) facilitate live updates in user interfaces and (ii) asynchronously manage dependencies between data structures. The latter case made it possible for a data structure to change its own value in response to a change made to a second data structure that was observing what was modified in the user interface. Both data structures would then asynchronously update their own observers, and the user interface would finally update dynamically. Such a complicated case as this is commonly used in ICE 2.0, and live updates to the user interface happen within every workflow task. RDF and OWL models in Apache Jena (and thus ICE 3.0) are available only at the highest level of the data model, and they are very coarse grained: They say only that the model changed, not what data structure in the model changed. This is a completely valid way to handle update notifications; but in contrast to the model of ICE 2.0, it requires a full reload of the data structures by clients, including user interfaces. It has the distinct advantage of using far less resources than the ICE 2.0 model, namely that it does not launch separate threads for each update, but it comes at the possible cost of an expensive reload with every significant update. However, there are numerous strategies for mitigating the performance cost of a large reload. The implications of a subtle change like this can be far reaching. For example, ICE 2.0 workflows that execute in ICE 3.0 will need to be broken into smaller pieces that divide any regions of dependency management into distinct steps. Alternatively, a decorator pattern could be implemented around the model to capture function calls and thereby identify which elements of the data model updated. This would, in effect, achieve the properties of the ICE 2.0 model using the new model provided through Apache Jena. \section{Using the Ontology for Interoperability} The ontology in Chapter \ref{ch:workflow-ontology} is shown by example to cover a range of workflows. Four of the five examples are workflows that can be executed, with two of the examples being executed from significantly different workflow engines, Eclipse ICE and Pegasus. Suppose that these four workflows were to be strung together into a single workflow that accomplishes the following: \begin{enumerate} \item Gathers some data using a threshold limiter \item Moves the data to a work directory \item Splits the data into smaller files \item Performs simulations using the data and some human feedback as input \item Moves the data and results back to the original directory \item Loops over all the files in the directory, deleting the unneeded ones \end{enumerate} This combined workflow campaign stitches some of the workflows together directly (steps 2--5) and splits the cycling and looping workflow to stage data. Conceptually, this is simple, but in practice it may require years of work. The remaining question of this work is whether or not the workflow ontology simplifies the execution of a workflow campaign, such as that described by this example; that is, does it help the workflow management systems charged with executing these workflows interoperate? The answer is that, in principle, it does because (i) the ontology supports nested workflows by domain and range restrictions on the workflow description and task classes and (ii) it provides a formal, common language for describing these different workflows that could not otherwise be described collectively. Together these two properties mean that any combination of workflows can be walked as a tree, split, and be (re)-combined so long as the workflows (ontology instances) are understood by the ``client'' workflow management systems. An alternative answer to this question is from the practical perspective of \S \ref{practicality}: In so far as the workflow ontology can describe workflows for different systems perfectly, it serves only to prove how different they are. Thus, practically, the answer is also that the ontology does not facilitate greater interoperability for workflows because it does not address the differences in software and present capabilities across workflow management systems, including the absence of any particular open application programming interfaces. This is a perspective that couples the execution of a workflow problem to the workflow management system made to solve it in the first place. How can these two positions be rectified? On the one hand, there is a promise of improved interoperability provided by machine-readable formality and rigor. On the other, there is the very practical point that most workflow management systems today are in closed ecosystems. The answer is that the workflow ontology should not be used for anything other than what it is: a means to formally describe, capture, and share information about workflows. It can fix only problems it was developed to solve. However, it can serve as an important decision-making tool and virtual road map for developers, designers, users, and project planners, while remaining usable by a select few tools to translate, decompose, cataloger, and investigate workflows. The formality and machine readability has certain other implications that are are discussed in Chapter \ref{ch:conclusions}. Effectively using the workflow ontology requires a graded approach. The following sections provide instructions for several use cases of the workflow ontology applied to practical workflow problems. \subsection{Typing Workflows} Chapter \ref{ch:introduction} includes details for multiple distinct types of workflows, and the workflow ontology can be used to categorize any workflow into these types. First, create a model of the workflow in question and visualize it (possibly using Graphviz). The type of workflow can be determined as follows: \begin{itemize} \item If the workflow is linear, with no loops, cycles, and directed dependencies, then the workflow is a high-throughput workflow based on a directed acyclic graph. \item If the workflow requires conditional behavior and external (possibly human) feedback and exhibits state changes, then it may be a modeling and simulation or similar type of workflow. \item If the workflow requires only tasks with few concrete parameters, properties, or anything that would make it executable, then it is a conceptual workflow. \item If the workflow appears to have an embedded workflow that is executed iteratively or repeatedly in a loop or threshold cycle, then it may be a testing, optimization, or analysis workflow. \end{itemize} \subsection{Comparing Workflows} Workflows can be compared directly using the workflow ontology. This is useful for workflows typed as described in the previous section or for workflows that are very similar to each other but described in separate and perhaps confusing description languages. First, create a model of two or more workflows using the workflow ontology, starting with the workflow description (root), tasks, actions, and task dependencies. If a precise relationship between the workflows (or lack thereof) cannot be determined because the tasks are too similar, continue to model the properties and, if necessary, any state changes in the model. This may be done either manually or by using RDF tools such as Apache Jena. Ontology and RDF model mergers are common features of these tools since the semantic underpinnings of RDF make it possible to compare graphs directly. The knowledge to use the ontology to determine whether or not two workflow models are similar is embedded in the graph structure itself. Nodes (tasks, actions, etc.) can be compared as the graphs are walked, either to neighbors at the same level or to different levels across the graphs. \subsection{Building Campaigns} Workflow campaigns can be built in a straightforward fashion once workflows have been typed, compared, and thoroughly analyzed. For workflows that can actually be executed, a new root-level workflow description must be created. Each distinct workflow description that will be part of the campaign can be added into the new parent workflow description through the ontology's ``executes'' object property, which can be applied to workflow descriptions as well as tasks. This produces a single workflow description with all subservient workflow descriptions in the same graph. Distributed workflow campaigns can be produced by using the ``hasHost'' property for workflow descriptions and tasks to indicate that the selected portion should be executed on the specified host. Alternatively, workflow campaigns can be created by simply subdividing workflows to create subworkflows that are executed on their own resources. This process works by identifying distinct branches of a workflow description and applying the ``hasHost'' property to the tasks of those branches. \section{Building an Interoperable Data, Provenance, and Workflow Metadata Management System} The previous discussion on interoperability (and much of this work at large) makes a very important assumption: it takes for granted that workflows and related artifacts can be easily shared. In practice, it may be very difficult to share real workflows and related artifacts because they are prohibitively large, exist on different networks, are stored in different layouts or orders (i.e. endianness), or require special privileges for access. This section describes the Basic Artifact Tracking System (BATS) that was developed as part of this thesis work to address data management, provenance, workflow metadata capture, and seamless sharing. BATS looks at sharing as a separable problem. Bulk data of meaningful values should be stored separately from metadata, and both of those should be managed separately from the search indices and sharing platform. It is beneficial (although not strictly required) for artifacts stored in BATS to have metadata described by one or more ontologies. In the very specific case of Eclipse ICE 3.0, this includes workflows built using the workflow ontology and data using the new Eclipse ICE data ontology mentioned in \S \ref{ice-data}. The discussion that follows focuses specifically on sharing provenance as a good working example, although as discussed this is virtually the same as storing the workflow data itself for a verbose and sophisticated provenance model. \baseInclude{pubs/billings-workflows-blockchain/content} \section{Summary} This chapter discusses various considerations for interoperability for scientific workflows. This includes examining different facets of interoperability and interchangeability. It also provides a practical example of where two workflow systems written by the same authors can suffer from real-world limitations in their programming that limit or prohibit interoperability. A detailed discussion of how the workflow ontology can be used in a graded approach to study and make decisions about workflows is also provided. It illustrates a problem faced by many new tools but especially this one: Promising opportunities would be available if tighter integration existed within the tooling stack. However, this situation limits only the usefulness of the workflow ontology as a programming tool; it still functions well as a tool for reasoning and discussing scientific workflows. The artifact tracking example provided in this chapter shows how ontological tools can be used to build new systems that are naturally interoperable, as well as how this type of work requires us to examine our most basic assumptions about how and when information is shared. This example is provided to illustrate how new technologies can leverage the workflow ontology from the outset to solve new problems. \baseInclude{pubs/billings-workflows-blockchain/conclusions} The next chapter considers these findings and other aspects of this work to draw conclusions about the value of ontological tools in the scientific workflow space.
\subsection{Service Clients}\label{p:client} This problem is designed to introduce the client-service structure. For this question you will be using our implemented service and writing your own client to create a slightly different single flower then before. See Figure~\ref{fig:2} for what the flower should look like. The work for this problem should be done in file \texttt{client.py}. \begin{figure}[h] \centering \includegraphics[width=150pt]{figures/p1/problem3.png} \caption{For Problem~\ref{p:client}. Service Clients} \label{fig:2} \end{figure} In \texttt{draw\_flower}: \begin{enumerate}[(a)] \item Initialize your node with the name \texttt{drawing\_turtle}. \item Wait for the service \texttt{draw}. \item Get a service handle for the draw service. Check \texttt{srv/Draw.srv} and \texttt{rospy} documentation for more information. \item Make a publisher that publishes to \texttt{/turtle1/cmd\_vel} with type \texttt{Twist} and queue size of 10 \item Make a 5Hz \texttt{Rate}. \item Loop, and: \begin{enumerate}[i.] \item Use the draw service to get the velocity message to publish. Look at \texttt{srv/Draw.srv} to determine the parameters and appropriate return name. \item Sleep for the previously created rate. \end{enumerate} \end{enumerate} In the main script: \begin{enumerate}[(a)] \item Call your function to draw the flower! \end{enumerate} In \texttt{client.launch}: \begin{enumerate}[(a)] \item Launch the turtlesim node. \item Launch the \texttt{draw\_service} node. \item Launch the \texttt{draw\_flower} node. \end{enumerate}
\chapter{Search} \section{Binary Search} \runinhead{Variants:} \begin{enumerate} \item get the idx equal or just lower (floor) \item get the idx equal or just higher (ceil) \item \pyinline{bisect_left} \item \pyinline{bisect_right} \end{enumerate} \subsection{idx equal or just lower} Binary search, get the idx of the element equal to or just lower than the target. The returned idx is the $A_{idx} \leq target$. It is possible to return $-1$. It is different from the \pyinline{bisect_lect}. \runinhead{Core clues:} \begin{enumerate} \item To get ``equal'', \pyinline{return mid}. \item To get ``just lower'', \pyinline{return lo-1}. \end{enumerate} $A_{idx} \leq target$. \begin{python} def bin_search(self, A, t, lo=0, hi=None): if hi is None: hi = len(A) while lo < hi: mid = (lo+hi)/2 if A[mid] == t: return mid elif A[mid] < t: lo = mid+1 else: hi = mid return lo-1 \end{python} \subsection{idx equal or just higher} $A_{idx} \geq target$. \begin{python} def bin_search(self, A, t, lo=0, hi=None): if hi is None: hi = len(A) while lo < hi: mid = (lo+hi)/2 if A[mid] == t: return mid elif A[mid] < t: lo = mid+1 else: hi = mid return lo \end{python} \subsection{bisect\_left} Return the index where to insert item x in list A. So if t already appears in the list, A.insert(t) will insert just before the \textit{leftmost} t already there. \runinhead{Core clues:} \begin{enumerate} \item Move \pyinline{lo} if $A_{mid} < t$ \item Move \pyinline{hi} if $A_{mid} \geq t$ \end{enumerate} \begin{python} def bisect_left(A, t, lo=0, hi=None): if hi is None: hi = len(A) while lo < hi: mid = (lo+hi)/2 if A[mid] < t: lo = mid+1 else: hi = mid return lo \end{python} \subsection{bisect\_right} Return the index where to insert item x in list A. So if t already appears in the list, A.insert(t) will insert just after the \textit{rightmost} x already there. \runinhead{Core clues:} \begin{enumerate} \item Move \pyinline{lo} if $A_{mid} \leq t$ \item Move \pyinline{hi} if $A_{mid} > t$ \end{enumerate} \begin{python} def bisect_right(A, t, lo=0, hi=None): if hi is None: hi = len(A) while lo < hi: mid = (lo+hi)/2 if A[mid] <= t: lo = mid+1 else: hi = mid return lo \end{python} \section{Applications} \subsection{Rotation} \runinhead{Find Minimum in Rotated Sorted Array.} Three cases to consider: \begin{enumerate} \item Monotonous \item Trough \item Peak \end{enumerate} If the elements can be duplicated, need to detect and skip. \begin{python} def findMin(self, A): lo = 0 hi = len(A) mini = sys.maxint while lo < hi: mid = (lo+hi)/2 mini = min(mini, A[mid]) if A[lo] == A[mid]: # JUMP lo += 1 elif A[lo] < A[mid] <= A[hi-1]: return min(mini, A[lo]) elif A[lo] > A[mid] <= A[hi-1]: # trough hi = mid else: # peak lo = mid+1 return mini \end{python} \section{Combinations} \subsection{Extreme-value problems}\label{extremeValueProblem} \runinhead{Longest increasing subsequence.} Array $A$. Clues: \begin{enumerate} \item \pyinline{MIN}: \textit{min} of index \textit{last} value of LIS of a particular \textit{len}. \item \pyinline{RET}: result table, store the $\pi$'s idx (predecessor); (optional, to build the LIS, no need if only needs to return the length of LIS) \item \pyinline{bin_search}: For each currently scanning index \pyinline{i}, if it smaller (i.e. $\neg$ increasing), to maintain the \pyinline{MIN}, binary search to find the position to update the min value. The \pyinline{bin_search} need to find the element $\geq$ to \pyinline{A[i]}. \end{enumerate} \newpage \begin{python} def LIS(self, A): n = len(A) MIN = [-1 for _ in xrange(n+1)] l = 1 for i in xrange(1, n): if A[i] > A[MIN[l]]: l += 1 MIN[l] = i else: j = self.bin_search(MIN, A, A[i], 1, l+1) MIN[j] = i return l \end{python} If need to return the LIS itself. \begin{python} for i in xrange(1, n): if A[i] > A[MIN[l]]: l += 1 MIN[l] = i RET[i] = MIN[l-1] # (RET) else: j = self.bin_search(MIN, A, A[i], 1, l+1) MIN[j] = i RET[i] = MIN[j-1] if j-1 >= 1 else -1 # (RET) # build the LIS (RET) cur = MIN[l] ret = [] while True: ret.append(A[cur]) if RET[cur] == -1: break cur = RET[cur] ret = ret[::-1] print ret \end{python} \section{High dimensional search} \subsection{2D} \runinhead{2D search matrix I.} $m\times n$ mat. Integers in each row are sorted from left to right. The first integer of each row is greater than the last integer of the previous row. $$ \begin{bmatrix} 1 & 3 & 5 & 7 \\ 10 & 11 & 16 & 20 \\ 23 & 30 & 34 & 50 \\ \end{bmatrix} $$ Row column search: starting at top right corner: $O(m+n)$. Binary search: search rows and then search columns: $O(\log m + \log n)$. \runinhead{2D search matrix II.} $m\times n$ mat. Integers in each row are sorted from left to right. Integers in each column are sorted in ascending from top to bottom. $$ \begin{bmatrix} 1& 4& 7& 11& 15 \\ 2& 5& 8& 12& 19 \\ 3& 6& 9& 16& 22 \\ 10& 13& 14& 17& 24 \\ 18& 21& 23& 26& 30 \\ \end{bmatrix} $$ Row column search: starting at top right corner: $O(m+n)$. Binary search: search rows and then search columns, but upper bound row and lower bound row: $$O\big(\min(n\log m, m\log n)\big)$$
\chapter{Experiments} \label{sec:chapterlabel4} In the previous chapter, deep reinforcement learning agents were described to solve the recommendation task. Now, in order to test and evaluate their performance, a simulated environment for Recommender Systems is going be defined. Then, after defining the baseline models and the experimental settings, two sets of experiments are carried out: (i) a performance evaluation of the proposed deep learning models and a pure Collaborative Filtering baseline model; and (ii) an analysis of the convergence and speed-up between the deep reinforcement learning agent based on previous work in the area, and an DRL agent with the new policy approach. Final conclusions on the experimental results obtained will be presented in the next chapter. \section{Reinforcement Learning Environment} For the purpose to demonstrate how the deep reinforcement learning agent perform on the recommendation task, a simulated environment is modelled under the OpenAI Gym\footnote{\url{https://gym.openai.com/}} reinforcement learning toolkit. It that allow us to define Partially Observed MDP environments (POMDPs) under an episodic setting where the agent's experience is broken down into a series of episodes \cite{brockman2016openai}. In general, OpenAI Gym manages two core concepts: (1) a free-to-code \textit{agent} that maximizes the convenience for users allowing them to implementation different styles of agent interface; and (2) a common \textit{environment} and action/observation interfaces that ease the implementation and testing of different reinforcement learning problems under the same framework. The final goal in OpenAI Gym is to maximize the expectation of total reward per episode, and to achieve a high level of performance in as few episodes as possible. During each episode, the agent's initial state is randomly sampled from a distribution, and the interaction proceeds until the environment reaches a terminal state. After performing an action step, the environment interface returns the observation of current state, the reward achieved by the action performed, a done flag indicating if an episode ends and an information object containing useful information for debugging and learning. Finally, the framework also allow us to measure the performance of a RL algorithm under an environment along two axes: \textit{final performance} or average reward per episode, after learning is complete; and, \textit{sample complexity} or the amount of time it takes to learn. \subsection{Recommender System Environment} The recommender system environment, characterized by a set of \textit{n} items to recommend to \textit{m} users, is defined (based on a previous definition in \cite{Dulac-Arnold2015}) as a sequence of MDPs $\langle \mathcal{A}, \mathcal{S}, r, \mathcal{P} \rangle$ composed by an action set $\mathcal{A}$ that correspond to set of items to recommend, a state space $\mathcal{S}$ holding the item the user is currently consuming, a reward $r$ defined as the rating value given by a user to an item if she accepts it, and a transition probability matrix $\mathcal{W}$ which defines the probability of that a user will accept item \textit{j} given that the last item she accepted was item \textit{i}. The transition probability matrix is generated using the ideas exposed by Yildirim et al. in \cite{yildirim2008random} to build a random walk recommender system using a Markov Chain mode,l where the probability of being in a state only depends on the previous step $Pr(X_{u, k+1} = i | X_{u, k})$. The algorithm presented in Appendix \ref{app:trans_prob_alg} details the underlying process to set up the environment. \subsection {Simulation algorithm} \label{sec:simalg} The implemented algorithm is presented in Appendix \ref{app:simulated_env} and describes the complete simulation process of the recommendation task. At each time-step, the agent presents an item \textit{i} to the user with action $\mathcal{A}_i$. The user then accepts the item according to the transition probability matrix $\mathcal{P}$ or selects a random item. To simulate the user patience in a session as in \cite{Dulac-Arnold2015}, an episode of learning ends with probability 0.1 if the user accepts the item, and with probability 0.2 if a random item is selected instead. Finally, after each episode the environment is reset by selecting a random item from a likely subset for an specific user provided by a single item-based collaborative filtering model based on the similarity between items. \section{Data Set} The 100-k and 1M Movielens datasets \cite{harper2016movielens} from the GroupLens Reseach Lab\footnote{\url{http://grouplens.org/datasets/movielens/}} are used to train and test the implemented deep reinforcement agents. Table \ref{table:dataset} summarizes the statistical properties of each dataset. The ratings files were pre-processed in order to generate the user rating matrix and the transition probability matrix. Additionally, train and test sets were generated to apply a five-fold cross validation to the baseline CF ratings predictor in the simulated environment. \section{Evaluation Scheme} For each model proposed below, we measure the average return obtained by the learning agent over steps, as well as the average precision along user sessions or episodes of learning. Finally, a quantitative and qualitative analysis of the results of each model are compared and contrasted against the performance of a random policy which acts randomly by sampling the next action to perform. \begin{table}[t] %\begin{center} \centering \begin{tabular}{ |l|r|r| } \hline % \multicolumn{2}{|c|}{100K Movielens} & 1M Movielens \\ & 100K Movielens & 1M Movielens \\ \hline Total ratings & 100,000 & 1,000,029 \\ Users & 943 & 6,040 \\ Movies & 1682 & 3,883 \\ Density & 0.63 & 0.42 \\ % Sparsity Level & 57.4\% \\ Mean ratings/user & 106 & 165 \\ Min. ratings/user & 20 & 20 \\ Max. ratings/user & 737 & 2314 \\ \hline \end{tabular} %\end{center} \caption{Properties of the 100-k and 1M Movielens datasets} \label{table:dataset} \end{table} \section{Baselines and Experimental Settings} To evaluate the strength and accuracy of the deep reinforcement learning model under the recommender system environment, we use two variants of the baseline model described in section \ref{sec:baseline}, and a model using the new policy architecture. These models are: \begin{itemize} %\item \textbf{FM-MCMC}: \textit{Factorization Machine with Monte Carlo Markov Chain inference} uses FM based on the Bayeasian inference with a Gibbs sampling technique that generates the distribution of $\hat{y}$ by sampling the conditional posterior distribution for each model parameter. This model was chosen as the baseline model for comparison as it it outperforms other learning approaches like SGD and ALS, and also because it integrates the regularization parameter into the model, which avoids a time-consuming search for the optimal hyperparameters. The only hyperparameter that remains for MCMC is the initialization of the standard deviation$\sigma$ for the Gibbs sampler. \item \textbf{DRL-kNN-CB}: the \textit{DRL using Content-based item similarity} model uses the DDPG algorithm with a bag-of-words feature vectors to represent actions and states. The k-nearest neighbours index is then created using the KDtree algorithm \cite{friedman1977algorithm} (with 30 leaf nodes cheked) to find the k-closest set of similar items $\mathcal{A}_k$ from the action estimated by the actor function. Finally, the Wolpertinger policy applies the action in $\mathcal{A}_k$ that yields to the maximum return. \item \textbf{DRL-kNN-CF}: the \textit{DRL with Item-based similarity} model uses the same policy and learning algorithm as the model described above but it implements an item-to item version of the k-NN algorithm by using the item vector representation from the user rating matrix. \item \textbf{DRL-FM}: the \textit{DRL with Factorization Machines policy} model replaces the k-NN algorithm from the models previously described with the BPR-FM model to return the Top-K items that can be recommended from a given state. Then, the FM-policy will select the action from the top-K recommendations that yields to the highest Q value in the long term. This model can be considered as a hybrid approach as the DDPG algorithm uses a content-based representation of items to estimate the next action, whereas the FM-policy rank items using the information in the user rating matrix. \end{itemize} % %For the FM models, we use the \textit{fastFM}\footnote{\url{https://github.com/ibayer/fastFM}} library introduced by Bayer I. in \cite{bayer2015fastfm} that offers an efficient python implementationn of the FM learning algorithms including MCMC and BRP-OPT with SGDthe ratings file was transformed to the $SVM^{light}$ representation introduced in \cite{joachims1999making}. The hyperparameters and network settings used in the experiments are detailed in Appendix \ref{app:hyperparameter}. The network configuration for the DDPG algorithm in the DRL-kNN-CB and DRL-FM models consist of a fully connected network with two hidden layers of 400 and 300 neurons each. f the DRL-kNN-CF model consists of two hidden layers of 1000 neurons. The input and output of the network are the current state (item previously recommended) and the item that the agents predicts to be the next recommendation, respectively. Therefore, their size depends on the vector representation of items in each model. For the DRL-kNN-CB model, feature vectors for each item were created using a combination of word embeddings extracted using \textit{word2vec}\footnote{\url{https://radimrehurek.com/gensim/index.html}}, and genre categorization as a binary vector. The final feature vector consists of 119 elements. Whereas, for the DRL-kNN-CF, items representation were extracted from the user rating matrix, so their size are 943 and 6040 elements for the 100-k and 1M datasets respectively. On the other hand, the network input in the DRL-FM model consists of 119 elements (as it uses the same item representation as the DRL-kNN-CB model). Nevertheless, the output size depends on the binary representation of the action set identifiers. For example, for the 100-k dataset, the output size is 11 as the maximum identifier number (1682: the total number of actions) can be represented using eleven binary digits ($1682_{10} = 11010010010_2$). To build the proposed policy architectures, we use the \textit{NearestNeighbors} model in the \textit{scikit-learn} library\footnote{\url{http://scikit-learn.org}} to train a k-NN model for the Wolpertinger policy using the KD-Tree algorithm, while for the FM-policy, a Ranking FM model is trained using the algorithm and default hyperparameter configuration provided in the \textit{Graphlab Create} API\footnote{\url{https://turi.com/products/create/}}. Finally, the DRL models are trained using a value of $k$ that corresponds to the 5\% of the action set size (which yielded to good performance in \cite{Dulac-Arnold2015}). In order to train and use the FM model, items and the current state respectively are formatted using the $SVM^{light}$ representation introduced in \cite{joachims1999making}. Figure \ref{fig:featurevector} presents an example of the feature vector used by the FM model, where the first $|\mathcal{U}|$ binary indicators variables (blue) represent the active user of a transaction, and the next $|\mathcal{I}|$ binary indicator variables (red) hold the active item. Each feature vector also contains normalized indicator variables (yellow) for all other items the user has ever rated. Finally, the vector contains a variable (green) holding the time when the rating was registered, and another variable containing information of the last item the user has rated before. \begin{figure}[t] \centering \includegraphics[scale=0.9]{images/featurevectors} \caption{Feature vector representation for the FM model. Source: \textit{Factorization machines} \cite{rendle2010factorization}} \label{fig:featurevector} \end{figure} The source code developed to train the models can be downloaded from \url{https://github.com/santteegt/ucl-drl-msc}. In general, we used Tensorflow\footnote{\url{https://www.tensorflow.org/}} to build the deep learning model with a soft placement compatibility, so experiments can be easily run in any computer even if it does have a GPU device or not. Further information about the implementation and the installation requirements to run the experiments can be found in Appendix \ref{app:implementation}. \section{Results} The following set of experiments used the 100k Movielens dataset and evaluate the performance of the proposed models at every 100 steps of learning. Due to the lack of computational resources, the experiments were carried out on a Macbook Pro 2.9 GHz Intel Core i5 with 8 GB RAM and results were analyzed after 20000 timesteps of learning (except for the DRL-kNN-CF model as it was only train using 10000 steps). Figure \ref{fig:return_train} shows the average return obtained by each agent during training while the \textit{train} column in Table \ref{table:return_table} summarizes the performance of each model along 5 different checkpoints of learning. It can be seen that our proposed policy architecture outperforms the baselines by obtaining a mean average return of $35$ with an slightly increasing progression of its performance during the process, whereas the DRL-kNN-CB model obtains less return during the first thousand episodes, but after 5000 steps it starts to get higher values and the average return stabilizes over $29$ approximately. As a result, the FM-policy is more efficient when finding items that yield to higher rewards than the Wolpertinger policy, evidencing that factorization machine learns latent factors that help to build a stronger policy architecture than k-NN. % %\begin{table}[t] %\centering %\begin{tabular}{ |l|r|r|r|r| } % \hline % Steps & \textbf{Random} & \textbf{DRL-kNN-CF} & \textbf{DRL-kNN-CB} & \textbf{DRL-FM}\\ % \hline % 0 & 8.95 & 3.6 & 8.06 & 11.81 \\ % 2,500 & 8.57 & 18.11 & 18.14 & 33.68 \\ % 5,000 & 8.06 & 20.06 & 31.04 & 39.82 \\ % 7,500 & 9.99 & 20.35 & 35.04 & 33.39 \\ % 10,000 & 10.7 & 20.67 & 30.32 & 36.55 \\ % 12,500 & 8.26 & - & 29.22 & 33.91 \\ % 15,000 & 10.84 & - & 26.72 & 32.97 \\ % 17,500 & 9.84 & - & 29.55 & 36.73 \\ % 20,000 & 9.84 & - & 32.88 & 38.73 \\ % \hline %\end{tabular} %\caption{Agent's performance during training in terms of average return} %\label{table:return_table} %\end{table} \begin{figure}[t] \centering \includegraphics[scale=0.6]{images/eval_return_train} \caption[Model average return during training]{Model average return during training} \label{fig:return_train} \end{figure} On the other hand, the DRL-kNN-CF approach does not outperform the content-based model, getting a mean average return of $ 20$ (approx.), mainly due to the dimensionality of the item representation and consequently the model network size. Its results reflect how the representation of the action space affects the behaviour of the k-NN based policy when finding the nearest item that produces the highest reward. Even though the model seems to have a very slow convergence behaviour, it obtains rewards significantly higher that a na{\"i}ive agent using a random policy. At the same time, we also evaluated the average precision gathered by each agent over episodes or user sessions. Figure \ref{fig:precision_train} shows that the precision of the DRL-kNN-CB model fluctuates on values near 0.9, while the DRL-kNN-CF obtains much lower precision since it starts learning and episodes later, accuracy values its precision over a user session falls between 0.4 and 0.6. The DRL-FM model, conversely, starts getting very low precision during the first episodes but then it increases sharply and maintains average precision values near one. This means that the model mostly provides good recommendations to users during a session and commit less errors than the baseline models. \begin{figure}[t] \centering \includegraphics[scale=0.5]{images/eval_precision_train} \caption{Average precision of recommendations during episodes of learning in the 100k Movielens recommender task} \label{fig:precision_train} \end{figure} As the simulated environment models the user patience by evaluating if a user consumed of not an item given by the agent, it is natural that the longer a session, the more efficient an agent model could be. So, after going further through the results obtained in the experiments, we also analyzed the number of recommendations computed by our best two agents during user sessions. The left plot in Figure \ref{fig:precision_att} presents the average number of recommended items in a session over the learning period. While the DRL-kNN-CB model learn from episodes with a range of 7-10 items, the DRL-FM model tends to experience user sessions where 8 or more items are involved. On the other hand, the right plot in Figure \ref{fig:precision_att} shows how the DRL-FM model also obtains higher precision@10 scores (around 0.6 to 0.7) than the baseline when acting over episodes. evidencing that even if the model obtains lower precision during the first iterations, the FM-policy is able boost the accuracy of recommendations and get more stable precision scores (over 0.6) than the Wolpertinger policy. \begin{figure}[t]\centering % \caption{\small Number of recommended items during user sessions and agents precision. (a) presents the average number of recommended items in a session over the learning period. (b) shows the averaged precision@10 obtained by agents in episodes} \begin{minipage}{0.49\textwidth} \centering \includegraphics[width=\linewidth]{images/itemspersession} \centering \small (a) Average number of items per user session \end{minipage} \begin {minipage}{0.49\textwidth} \centering \includegraphics[width=\linewidth]{images/precision_at_10} \small (b) Precision@10 of agents \end{minipage} \caption{\small Number of recommended items during user sessions and underlying agents precision.} \label{fig:precision_att} \end{figure} Additionally, and with the purpose of demonstrate the importance of the exploration/exploitation trade-off, we test the models by switching off learning (and hence exploration of items)after every 100 steps of training to evaluate how the reinforcement agents act by just exploiting the current learned model parameters. Results are presented in Figure \ref{fig:return_test} and Figure \ref{fig:precision_test}. As can be seen, the behaviour of the DRL-kNN-CF model and the random policy does not change, but the performance of the DRL-kNN-CB model is now approximately similar to the DRL-FM model, obtaining a mean average return of approximately $34$ and $35$ respectively. \begin{figure}[t] \centering \includegraphics[scale=0.6]{images/eval_return_test} \caption{Agent's performance by pure exploitation of the model} \label{fig:return_test} \end{figure} \begin{table}[t] \centering \begin{tabular}{ |l|r|r|r|r|r|r|r|r| } \hline & \multicolumn{2}{|c|}{\textbf{Random}} & \multicolumn{2}{|c|}{\textbf{DRL-kNN-CF}} & \multicolumn{2}{|c|}{\textbf{DRL-kNN-CB}} & \multicolumn{2}{|c|}{\textbf{DRL-FM}}\\ \hline \hline Steps & Train & Exploit & Train & Exploit & Train & Exploit & Train & Exploit \\ \hline \hline 0 & 8.95 & 9.23 & 3.60 & 2.48 & 8.06 & 10.44 & 11.81 & 0 \\ 2,500 & 8.57 & 9.12 & 18.11 & 27.79 & 18.14 & 18.64 & 33.68 & 33.01 \\ 5,000 & 8.06 & 9.30 & 20.06 & 29.32 & 31.04 & 30.03 & 39.82 & 33.29 \\ 7,500 & 9.99 & 8.36 & 20.35 & 30.04 & 35.04 & 37.26 & 33.39 & 35.53 \\ 10,000 & 10.70 & 10.22 & 20.67 & 22.17 & 30.32 & 36.83 & 36.55 & 40.97 \\ 12,500 & 8.26 & 10.52 & - & - & 29.22 & 38.80 & 33.91 & 33.23 \\ 15,000 & 10.84 & 7.91 & - & - & 26.72 & 31.52 & 32.97 & 32.66 \\ 17,500 & 9.84 & 11.15 & - & - & 29.55 & 35.06 & 36.73 & 38.13 \\ 20,000 & 9.80 & 11.15 & - & - & 32.88 & 34.60 & 38.73 & 34.08 \\ \hline \end{tabular} \caption{Agent's performance in terms of average return} \label{table:return_table} \end{table} In terms of average precision over user sessions, both models have episodes where the precision of recommended items lies between 0.9 and 1. Even if it seems to be a good behaviour for an agent, we found certain cases where the same item is recommended more than twice under the same user session, and which can lead possible flaw when users interests are to find new items. This scenario appears as the simulated environment does not take into account diversity of items being recommended. Finally, Table \ref{table:return_table} summarizes the performance of agents under both configurations. The DRL-kNN-CB model is able to reach a similar performance than DRL-FM by pure exploitation of the model parameters at certain times. On the other hand, the DRL-FM model does not get any reward (and thus is not able to recommend) during the first steps, but then it starts giving good recommendations and getting reward values close to those obtained during training. Therefore, the need to define an exploration/exploitation trade-off under a policy will allow a balance between both behaviours to, for example to obtain higher reward by exploiting the learned DRL-kNN-CB model while keeping learning at the same time. \begin{figure}[!t] \centering \includegraphics[scale=0.6]{images/eval_precision_test} \caption{Average precision of recommendations by pure exploitation of the model} \label{fig:precision_test} \end{figure}
\section*{Exercises} \begin{ex} Which of the following sets are subspaces of $\R^3$? Explain. \begin{enumerate} \item $V_1=\set{\left.\vect{u}=\begin{mymatrix}{c} u_1 \\ u_2 \\ u_3 \end{mymatrix}~\right\vert~ \abs{u_1} \leq 4}$. \item $V_2=\set{\left.\vect{u}=\begin{mymatrix}{c} u_1 \\ u_2 \\ u_3 \end{mymatrix}~\right\vert~\text{$u_i\geq 0$ for each $i=1,2,3$}}$. \item $V_3=\set{\left.\vect{u}=\begin{mymatrix}{c} u_1 \\ u_2 \\ u_3 \end{mymatrix}~\right\vert~ u_3+u_1=2u_2}$. \item $V_4=\set{\left.\vect{u}=\begin{mymatrix}{c} u_1 \\ u_2 \\ u_3 \end{mymatrix}~\right\vert~ u_3\geq u_1}$. \item $V_5=\set{\left.\vect{u}=\begin{mymatrix}{c} u_1 \\ u_2 \\ u_3 \end{mymatrix}~\right\vert~ u_3=u_1=0}$. \end{enumerate} \begin{sol} \begin{enumerate} \item No. We have $\begin{mymatrix}{r} 1 \\ 0 \\ 0 \\ 0 \end{mymatrix} \in V_1$ but $10\begin{mymatrix}{r} 1 \\ 0 \\ 0 \\ 0 \end{mymatrix} \notin V_1$. \item This is not a subspace. The vector $\begin{mymatrix}{r} 1 \\ 1 \\ 1 \\ 1 \end{mymatrix}$ is in $V_2$. However, $(-1) \begin{mymatrix}{r} 1 \\ 1 \\ 1 \\ 1 \end{mymatrix}$ is not. \item This is a subspace. It contains the zero vector and is closed with respect to vector addition and scalar multiplication. \item This is not a subspace. The vector $\begin{mymatrix}{r} 0 \\ 0 \\ 1 \\ 0 \end{mymatrix}$ is in $V_4$. However $(-1) \begin{mymatrix}{r} 0 \\ 0 \\ 1 \\ 0 \end{mymatrix} = \begin{mymatrix}{r} 0 \\ 0 \\ -1 \\ 0 \end{mymatrix}$ is not. \item This is a subspace. It contains the zero vector and is closed with respect to vector addition and scalar multiplication. \end{enumerate} \end{sol} \end{ex} \begin{ex} Let $\vect{w}\in \R^4$ be a given fixed vector. Let \begin{equation*} M=\set{\left.\vect{u} =\begin{mymatrix}{c} u_1 \\ u_2 \\ u_3 \\ u_4 \end{mymatrix} \in \R^4~\right\vert~ \vect{w}\dotprod \vect{u} =0}. \end{equation*} Is $M$ a subspace of $\R^4$? Explain. \begin{sol} Yes, this is a subspace because it contains the zero vector and is closed with respect to vector addition and scalar multiplication. For example, if $\vect{u},\vect{v}\in M$, then $\vect{w}\dotprod\vect{u}=0$ and $\vect{w}\dotprod\vect{v}=0$, therefore $\vect{w}\dotprod(\vect{u}+\vect{v})=0$, therefore $\vect{u}+\vect{v}\in M$. \end{sol} \end{ex} \begin{ex} Let $\vect{w},\vect{v}$ be given vectors in $\R^4$ and define \begin{equation*} M=\set{\left.\vect{u}=\begin{mymatrix}{c} u_1 \\ u_2 \\ u_3 \\ u_4 \end{mymatrix} \in \R^4 ~\right\vert~ \text{$\vect{w}\dotprod \vect{u}=0$ and $\vect{v}\dotprod \vect{u}=0$}}. \end{equation*} Is $M$ a subspace of $\R^4$? Explain. \begin{sol} Yes, this is a subspace. \end{sol} \end{ex} \begin{ex} In this exercise, we use scalars from the field $\Z_2$ of integers modulo $2$ instead of real numbers (see Section~\ref{sec:fields}, ``Fields''). Which of the following sets are subspaces of $(\Z_2)^3$? \begin{enumerate} \item $V_1 = \set{ \begin{mymatrix}{r} 1 \\ 1 \\ 0 \end{mymatrix}, \begin{mymatrix}{r} 0 \\ 1 \\ 1 \end{mymatrix}, \begin{mymatrix}{r} 1 \\ 0 \\ 1 \end{mymatrix}, \begin{mymatrix}{r} 0 \\ 0 \\ 0 \end{mymatrix} }$. \item $V_2 = \set{ \begin{mymatrix}{r} 1 \\ 1 \\ 1 \end{mymatrix}, \begin{mymatrix}{r} 1 \\ 1 \\ 0 \end{mymatrix}, \begin{mymatrix}{r} 1 \\ 0 \\ 0 \end{mymatrix}, \begin{mymatrix}{r} 0 \\ 0 \\ 0 \end{mymatrix} }$. \item $V_3 = \set{ \begin{mymatrix}{r} 0 \\ 0 \\ 0 \end{mymatrix} }$. \item $V_3 = \set{ \begin{mymatrix}{r} 1 \\ 1 \\ 1 \end{mymatrix}, \begin{mymatrix}{r} 1 \\ 0 \\ 0 \end{mymatrix}, \begin{mymatrix}{r} 0 \\ 1 \\ 0 \end{mymatrix}, \begin{mymatrix}{r} 0 \\ 0 \\ 1 \end{mymatrix} }$. \end{enumerate} \begin{sol} \begin{enumerate} \item $V_1$ is a subspace. \item $V_2$ is not a subspace: not closed under addition. For example, \begin{equation*} \begin{mymatrix}{r} 1 \\ 1 \\ 1 \end{mymatrix} \in V_2,\quad \begin{mymatrix}{r} 1 \\ 1 \\ 0 \end{mymatrix} \in V_2,\quad \mbox{but}\quad \begin{mymatrix}{r} 1 \\ 1 \\ 1 \end{mymatrix} + \begin{mymatrix}{r} 1 \\ 1 \\ 0 \end{mymatrix} = \begin{mymatrix}{r} 0 \\ 0 \\ 1 \end{mymatrix} \not\in V_2. \end{equation*} \item $V_3$ is a subspace. \item $V_4$ is not a subspace. For example, it does not contain the zero vector. \end{enumerate} \end{sol} \end{ex} \begin{ex} Suppose $V, W$ are subspaces of $\R^n$. Let $V\cap W$ be the set of all vectors that are in both $V$ and $W$. Show that $V\cap W$ is also a subspace. \begin{sol} Because $\vect{0}\in V$ and $\vect{0}\in W$, we have $\vect{0}\in V\cap W$. To show that $V\cap W$ is closed under addition, assume $\vect{u},\vect{v}\in V\cap W$. Then $\vect{u},\vect{v}\in V$, and since $V$ is a subspace we have $\vect{u}+\vect{v}\in V$. Similarly $\vect{u},\vect{v}\in W$, and since $W$ is a subspace we have $\vect{u}+\vect{v}\in W$. It follows that $\vect{u}+\vect{v}$ is in both $V$ and $W$, and therefore in $V\cap W$. To show that $V\cap W$ is closed under scalar multiplication, assume $\vect{u}\in V\cap W$ and $k\in\R$. Then $\vect{u}\in V$, and therefore $k\vect{u}\in V$. Similarly $k\vect{u}\in W$, and therefore also $k\vect{u}\in V\cap W$. \end{sol} \end{ex} \begin{ex} Let $V$ be a subset of $\R^n$. Show that $V$ is a subspace if and only if it is non-empty and the following condition holds: for all $\vect{u},\vect{v}\in V$ and all scalars $a,b\in\R$, \begin{equation*} a\vect{u} + b\vect{v} \in V. \end{equation*} \end{ex} \begin{ex} Let $\vect{u}_1,\ldots,\vect{u}_k$ be vectors in $\R^n$, and let $S=\sspan\set{\vect{u}_1,\ldots,\vect{u}_k}$. Show that $S$ is the {\em smallest} subspace of $\R^n$ that contains $\vect{u}_1,\ldots,\vect{u}_k$. Specifically, this means you have to show: if $V$ is any other subspace of $\R^n$ such that $\vect{u}_1,\ldots,\vect{u}_k\in V$, then $S\subseteq V$. \end{ex}
\documentclass[10pt,a4paper]{this} \usepackage{lipsum} \begin{document} \title{this} \author{@0xlarge} \maketitle \section*{section} \paragraph{paragraph} \lipsum*[1][1-2] \begin{itemize} \item \lipsum*[1][1] \item \lipsum*[1][2] \item \lipsum*[1][3] \item \lipsum*[1][4] \end{itemize} \lipsum \end{document}
\documentclass[main.tex]{subfiles} \begin{document} \marginpar{Monday\\ 2020-12-21, \\ compiled \\ \today} Let us continue with gauge-invariant cosmological perturbations. Let us now give a gauge-invariant definition for the matter velocity: % \begin{align} \label{eq:matter-velocity-gauge-invariant} 2 v _{s} = 2 v^{\parallel} + \chi^{\parallel, \prime} \,, \end{align} % where, as usual, by ``matter'' we mean anything which goes on the right-hand side of the Einstein equations, and \(s\) means ``scalar''. This velocity is related to the amplitude of the \textbf{shear tensor} for the matter velocity: specifically, from the shear tensor \(\sigma_{\mu \nu }\) we can define the quantity \(\qty(\sigma^{ij} \sigma_{ij} /2 )^{1/2}\). For the scalar part, we have (following the notation by Bardeen) % \begin{align} \epsilon_m &= \delta \rho + \rho_0' \qty(v^{\parallel} + \omega^{\parallel} ) \\ \rho_0 &= \rho_0 (\eta ) \,. \end{align} Note that energy density perturbations themselves are not gauge invariant. The quantity \(\epsilon _m\) corresponds to \(\delta \rho \) in the gauge where \(v^{\parallel} + \omega^{\parallel} = 0\), which means that we are selecting constant-\(\eta \) hypersurfaces which are orthogonal to the worldlines of the fluid: the fluid's rest frame. The quantity \(v^{\parallel} + \omega^{\parallel}\) enters into the expression for \(T^{0}_{i}\), which describes the momentum flux of the fluid. We also define % \begin{align} 2 E_g = 2 \delta \rho + \rho_0' \qty(2 \omega^{\parallel} - \chi^{\parallel, \prime}) \,, \end{align} % which is also equal to \(\delta \rho \) in the gauge in which \(2 \omega^{\parallel} - \chi^{\parallel, \prime} = 0\), which is the zero-shear or Poisson gauge. We can also construct one vector perturbation, since we start with two and remove one with the gauge degree of freedom described as \(d^{i}\): % \begin{align} \Psi_i = \omega^{\perp}_i - \chi_i^{\perp, \prime} \,. \end{align} This is related to the amplitude of the vector geometric component of the geometric shear \(\sigma_{\mu \nu }\). This term describes frame-dragging effects. The matter velocity can be described as % \begin{align} V^{i}_{s} = v^{i}_{\perp} + \chi^{i, \prime}_{\perp} \marginnote{Compare to \eqref{eq:matter-velocity-gauge-invariant}.} \,. \end{align} Also, we can define % \begin{align} V^{i}_{c} = v^{i}_{\perp} + \omega^{i}_{\perp} \,. \end{align} This is related to the amplitude of the vorticity\footnote{Local angular velocity of fluid elements} tensor \(\omega_{\mu \nu }\) (and, specifically, the quantity \(\qty(\omega^{ij} \omega_{ij} / 2)^{1/2}\)). As for tensor perturbation modes, linear tensor perturbations are automatically gauge-invariant (at linear order, at least): % \begin{align} \chi^{T, \prime}_{ij} = \chi^{T}_{ij} \,. \end{align} \section{Perturbed Einstein Equations} Let us write the equations of motion for these linear cosmological perturbations. We start from the Einstein equations \(G_{\mu \nu } = 8 \pi G T_{\mu \nu }\), and the Bianchi identities \(T^{\mu \nu }_{; \nu } = 0\). The Einstein tensor is defined as % \begin{align} G_{\mu \nu } &= R_{\mu \nu } - \frac{1}{2} g_{\mu \nu } R \\ R_{\mu \nu } &= R^{\alpha }_{\mu \alpha \nu } \\ R^{\alpha }_{\mu \nu \beta }&\sim \pdv{\Gamma }{x} + \Gamma^2 \\ \Gamma^{\mu }_{\nu \rho } &\sim g^{-1} \pdv{g}{x} \,. \end{align} We can compute the nonvanishing Christoffel symbols in the unperturbed case (see, for example, the notes for Theoretical Cosmology), and then the perturbations of these; note that the inverse of a perturbed metric can be computed by inverting the perturbation according to the flat metric only (see \cite[eq.\ 8.20]{tissinoGeneralRelativityExercises2020}): % \begin{align} \delta \Gamma^{0}_{00} &= \psi ' \\ \delta \Gamma^{0}_{0i} &= \partial_{i} \psi + \frac{a'}{a} \partial_{i} \omega^{\parallel} \\ \delta \Gamma^{i}_{00} &= \frac{a'}{a} \partial^{i} \omega^{\parallel} + \partial^{i} \omega^{\parallel, \prime} + \partial^{i} \psi \\ \delta \Gamma^{0}_{ij} &= -2 \frac{a'}{a} \psi \delta_{ij} - \partial_{i} \partial_{j} \omega^{\parallel} - 2 \frac{a'}{a} \phi \delta_{ij} - \phi ' \delta_{ij} + \frac{a'}{a} D_{ij} \chi^{\parallel} + \frac{1}{2} D_{ij} \chi^{\parallel, \prime} \\ \delta \Gamma^{i}_{0j} &= - \phi \delta^{i}_{j} + \frac{1}{2} D^{i}_{j} \chi^{\parallel, \prime} \\ \delta \Gamma^{i}_{jk} &= \dots \,. \end{align} The spatial components of the metric can be written as % \begin{align} g_{ij} = \underbrace{a^2(\eta ) \qty[1 - 2 \phi ] \delta_{ij}}_{a^2(\eta , \vec{x})} + \dots \,, \end{align} % where we can express % \begin{align} a(\eta , \vec{x}) = a(\eta ) \qty(1 - \phi (\eta , \vec{x})) \,, \end{align} % therefore \(\delta a = - a \phi \), which means that % \begin{align} \delta \qty( \frac{a^{\prime}}{a}) = - \phi ' \,. \end{align} The unperturbed Ricci tensor reads % \begin{align} R_{00} &= - 3 \frac{a''}{a} + 3 \qty( \frac{a'}{a})^2 \\ R_{ij} &= \qty[\frac{a''}{a} + \qty(\frac{a'}{a})^2] \delta_{ij} \,. \end{align} Its perturbation is % \begin{align} \delta R_{00} &= \frac{a'}{a} \nabla^2 \omega^{\parallel} + \nabla^2 \omega^{\parallel, \prime} + 3 \phi^{\parallel} + 3 \frac{a'}{a} \phi' + 3 \frac{a'}{a} \psi ' \\ \delta R_{0i} &= \frac{a'}{a} \partial_{i} \omega^{\parallel} + \qty(\frac{a'}{a})^2 \partial_{i} \omega^{\parallel} +2 \partial_{i} \phi' + 2 \frac{a'}{a} \partial_{i} \psi + \frac{1}{2} \partial_{k} D^{k}_i \qty(\chi_{\parallel})' \\ \delta R_{ij} &= \dots \,. \end{align} \todo[inline]{Copy full expressions from the notes.} The Ricci scalar \(R\) is given by \(R = (6/a^2) (a' / a)\) in flat FRLW, while its perturbation is % \begin{align} \delta R &= \frac{1}{a^2} \qty(- 6 \frac{a'}{a} \nabla^2\omega^{\parallel} - 2 \nabla^2 \omega^{\parallel, \prime} - 2 \nabla^2 \psi - 6 \phi^{\parallel} - 6 \frac{a'}{a} \psi' - 18 \frac{a'}{a} \phi ' - 12 \frac{a''}{a} \psi + 4 \nabla^2 \phi + \partial_{k} \partial^{i} D^{k}_{i} \chi^{\parallel}) \,. \end{align} This expression is fully general, in a specific gauge it can be significantly simplified. The stress-energy tensor we will use is given by % \begin{align} T_{\mu \nu } = \rho u_\mu u_\nu + p h_{\mu \nu } + \Pi_{\mu \nu } \,, \end{align} % where \(\Pi^{\mu }_{\mu } = \Pi_{\mu \nu } u^{\nu } = 0\). This allows us to account for imperfections in the fluid. The only nonvanishing components of \(\Pi \) are the spatial ones \(\Pi_{ij}\). This is true in any frame. We can write it as % \begin{align} \Pi_{ij} = D_{ij} \Pi^{\parallel} + 2\Pi^{\perp}_{(i, j)} + \Pi^{T}_{ij} \,, \end{align} % where, as usual, \(D_{ij} = \partial_{i} \partial_{j} - (1/3) \delta_{ij} \nabla^2\). The component % \begin{align} - T^{0}_{0} &= \rho_{0} (\eta ) + \delta \rho (\eta , \vec{x}) \\ &= \rho_0 (\eta ) \qty(1 + \delta ) \,, \end{align} % while % \begin{align} p = p_0 (\eta ) \qty(1 + \Pi _L) \,, \end{align} % where \(\Pi _L = \delta p / p_0 (\eta )\). The \(L\) stands for ``longitudinal''. The unperturbed spatial components of the stress-energy tensor read: % \begin{align} T^{i}_{j} &= p_0 (\eta ) \qty[ \qty(1 + \Pi _L) \delta^{i}_{j} + \Pi_{T, j}^{i}] \\ \Pi_{T, j}^{i} &= \eval{\frac{\Pi^{i}_{j}}{p_0 (\eta )}}_{\text{traceless}} \,. \end{align} The perturbation reads % \begin{align} \delta T^{0}_{i} = \qty(\rho_0 + p_0 ) \qty(v_i + \omega _i ) & \text{or} & \delta T^{i}_{0} = - (\rho_0 + p_0 ) v^{i} \,. \end{align} This is quite general: it is the density of the \(i\)-component of the fluid's momentum, or the flux of energy in the \(i\)-th direction. The linearly perturbed \(00\) EFE for scalar perturbation (as they are decoupled from the vector and tensor ones) reads % \begin{align} \frac{3 a'}{a} \qty(\hat{\phi}' + \frac{a'}{a} \psi ) - \nabla^2 \qty(\hat{\phi} + \frac{a'}{a} \sigma ) = - 4 \pi G a^2 \delta \rho \,, \end{align} % where \(\hat{\phi} = \phi + (1/6) \nabla^2 \chi^{\parallel}\) and \(\sigma = - \omega^{\parallel} + (1/2) \chi^{\parallel, \prime}\). The \(0i\) equation is % \begin{align} \hat{\phi}' + \frac{a'}{a} \psi = - 4 \pi G a^2 \qty(\rho_0 + p_0 )V \,, \end{align} % where \(V = v^{\parallel} + \omega^{\parallel}\). These two are not really ``evolution'' equations, they should be interpreted as constraints (to relate with \(\delta T_{00} \) and \(\delta T_{0i}\)) for the evolution of the other components. On the other hand, from the trace of the \(ij\) equations we find % \begin{align} \hat{\phi}'' + 2 \frac{a'}{a} \hat{\phi}' + \frac{a'}{a} \psi + \qty[2 \qty(\frac{a'}{a})' + \qty(\frac{a'}{a})^2] \psi = 4 \pi G a^2 \qty(\Pi _L + \frac{2}{3} \nabla^2 \Pi _T)p_0 \,, \end{align} % where the \(T\) in \(\Pi _T = \Pi^{\parallel} / p_0 (\eta )\) means ``traceless''. From the traceless part of these equations we find % \begin{align} \sigma ' + 2 \frac{a'}{a} \sigma + \hat{\phi} - \psi = 8 \pi G a^2 \Pi _T p_0 \,. \end{align} So far we have not chosen a gauge; let us now put ourselves in the Poisson gauge. Here, % \begin{align} \omega^{\parallel} = 0 = \chi^{\parallel} \,. \end{align} Then, \(\hat{\phi} = \phi = - \Phi _H\), and \(\psi = \Psi _A\). Now \(\sigma = - \omega^{\parallel} + (1/2) \chi^{\parallel, \prime} = 0\). Then, the equations reads % \begin{align} \phi - \psi &= 8 \pi G a^2 \Pi_T p_0 \\ \Phi _H + \Psi _A &= - 8 \pi G a^2 \Pi _T p_0 \,. \end{align} If the anisotropic stress can be neglected, then \(\phi = \psi \); this is the case for CDM, not so for nonisotropic relativistic particles or modified gravity. If this is the case, then we can write the evolution equation in a simpler way: \(\Pi _T\) vanishes, by definition \(\Pi _L p_0 = \delta p\), which we can split into % \begin{align} \delta p = c_s^2 \delta \rho + \delta p _{\text{non-adiab}} \,, \end{align} % and considering only the adiabatic part we find % \begin{align} \Phi _H'' + 3 \qty(1 + c_s^2) \frac{a'}{a} \Phi _H' + \qty[2 \qty(\frac{a'}{a})' + \qty(1 + 3 c_s^2) \qty(\frac{a'}{a})^2 - c_s^2 \nabla^2] \Phi _H = 0 \,, \end{align} % which is an isolated evolution equation for \(\Phi _H\), a wave-like propagation equation. The Poisson gauge is the most Newton-like one: the evolution equation becomes % \begin{align} - \nabla^2 \Phi _H &= 4 \pi G a^2 \underbrace{\qty(\delta \rho - \frac{3 a'}{a} (\rho_0 + p_0 )V )}_{\epsilon_{m}} \marginnote{Inserting the \(0i\) equation into the \(00\) one.} \\ &= 4 \pi G a^2\epsilon_m \,, \end{align} % a Poisson equation. For the vector perturbation \(\Psi_i\), we find (from the \(0i\) equation) % \begin{align} \nabla^2\Psi _i = 16 \pi G a^2 \qty(\rho_0 + p_0 ) V_{i, c} \,, \end{align} % while for the tensor perturbations, starting from the traceless part of the \(ij\) EFE, we get % \begin{align} \chi_{ij}^{\prime \prime, T} + 2 \frac{a'}{a} \chi^{T, \prime}_{ij} - \nabla^2 \chi^{T}_{ij} = 16 \pi G a^2p_0 (\eta ) \Pi^{T}_{ij} \,. \end{align} We should also perturb for the matter source of the equations: \(T^{\mu \nu }_{; \nu } =0 \). The energy density continuity equation (\(\mu = 0\)) reads % \begin{align} \label{eq:energy-density-continuity-equation} \delta \rho ' + \frac{3 a'}{a} \qty(\delta p + \delta \rho ) - 3 \qty(\rho_0 + p_0 ) \hat{\phi}' + \qty(\rho_0 + p_0 ) \nabla^2 \qty(V + \sigma ) &= 0 \,, \end{align} % while for \(\mu = i\) we get % \begin{align} V' + \qty(1 + 3 c_s^2) \frac{a'}{a} V + \psi + \frac{1}{(\rho_0 + p_0 )} \qty(\delta p + \frac{2}{3} p_0 \nabla^2 \Pi _T) &= 0 \,. \end{align} The curvature perturbation on uniform energy density hypersurfaces is % \begin{align} \zeta = - \hat{\phi} - H \frac{ \delta \rho }{\dot{\rho}_0 } = - \hat{\phi} - \frac{a'}{a} \frac{ \delta \rho }{\rho_0 '} \,, \end{align} % where, as usual, \(\hat{\phi} = \phi + (1/6) \nabla^2 \chi^{\parallel}\). In a uniform energy density gauge \(\zeta = - \hat{\phi}\); also in the flat gauge we have \(\hat{\phi} = 0\), which tells us that \(\zeta \) is an energy density perturbation. On super-horizon scales and taking equation \eqref{eq:energy-density-continuity-equation} in the gauge where \(\delta \rho = 0\), the Laplacian in the energy density continuity equation can be taken to vanish (\(k \ll 1\)), and we can express it as % \begin{align} \zeta ' = - \frac{a'}{a} \frac{ \delta p}{\rho_0 + p_0 } \,, \end{align} % but we must evaluate this in the uniform energy density gauge the adiabatic contribution to the pressure perturbation vanishes, therefore we are left with % \begin{align} \zeta ' = - \frac{a'}{a} \frac{ \delta p _{\text{non-adiabatic}}}{\rho_0 + p_0 } \,. \end{align} For single-field models of slow-roll inflation, we find that on super-horizon scales % \begin{align} \delta p _{\text{non-adiabatic}} \propto \frac{k^2 \Phi _H}{a^2} \approx 0 \implies \zeta \approx \const \,. \end{align} The continuity equation for vector perturbations reads % \begin{align} \qty[(\rho_0 +p_0 ) V_{ic}]' + \frac{4 a'}{a} (\rho_0 + p_0 ) V_{ic} = - \nabla_k \qty(\Pi^{\perp k}_{, i} + \Pi^{\perp, k}_{i}) \,. \end{align} By Kelvin's circulation theorem, vorticity is conserved along trajectories unless there are dissipative effects. Then, the divergence on the right-hand side of this equation vanishes, therefore we can write the left-hand side as % \begin{align} a^3 \qty(\rho_0 + p_0 ) V_{ic} a = \const \,. \end{align} This amounts to a momentum times \(a\), so the equation represents the conservation of the intrinsic angular momentum. \end{document}
\documentclass[12pt]{cdblatex} \usepackage{fancyhdr} \usepackage{footer} \begin{document} % ================================================================================================= % create checkpoint file \bgroup \CdbSetup{action=hide} \begin{cadabra} import cdblib checkpoint_file = 'tests/semantic/output/geodesic-lsq-midpt.json' cdblib.create (checkpoint_file) checkpoint = [] \end{cadabra} \egroup % ================================================================================================= \section*{Geodesic mid-point for arc-length} \input{metric.cdbtex} \input{geodesic-lsq.cdbtex} This code uses the results of {\tts geodesic-lsq} and {\tts metric} to show that the 2nd and 3rd order estimates for $L^2_{PQ}$ can be recovered using a mid-point estimate. For the 3rd order estimate we have \begin{align*} g_{ab}(x) &= \cdb{gab4.601} + \BigO{\eps^4}\\ L^2_{PQ} &= \cdb{lsq4.301} + \BigO{\eps^4} \end{align*} The code below verifies that \begin{equation*} L^2_{PQ} = g_{ab}(\bar x) Dx^{a} Dx^{b} + \BigO{\eps^4} \end{equation*} where $\bar x$ is the \emph{coordinate} midpoint of the geodesic \begin{equation*} {\bar x^a} = \frac{1}{2}\left(x^{a}_{P} + x^{a}_{Q}\right) \end{equation*} This result holds true only for the 2nd and 3rd order estimates. Note that the \emph{coordinate} midpoint is not the \emph{geometric} midpoint of the geodesic. It might be interesting to see if the higher order estimates could be recovered by sampling the metric at points other than the mid point. \clearpage \begin{cadabra} {a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w#}::Indices(position=independent). \nabla{#}::Derivative. g_{a b}::Metric. g^{a b}::InverseMetric. R_{a b c d}::RiemannTensor. import cdblib gab = cdblib.get('g_ab','metric.json') lsq2 = cdblib.get('lsq2','geodesic-lsq.json') lsq3 = cdblib.get('lsq3','geodesic-lsq.json') lsq4 = cdblib.get('lsq4','geodesic-lsq.json') lsq5 = cdblib.get('lsq5','geodesic-lsq.json') substitute (gab,$x^{a}->(p^{a}+q^{a})/2$) # evaluate rnc gab at mid-point distribute (gab) defgab := g_{a b} -> @(gab). mid := g_{a b} (q^{a}-p^{a}) (q^{b}-p^{b}). substitute (mid,defgab) distribute (mid) sort_product (mid) rename_dummies (mid) canonicalise (mid) tst2 := @(lsq2) - @(mid). # cdb (tst2.201,tst2) tst3 := @(lsq3) - @(mid). # cdb (tst3.201,tst3) tst4 := @(lsq4) - @(mid). # cdb (tst4.201,tst4) tst5 := @(lsq5) - @(mid). # cdb (tst5.201,tst5) substitute (tst2,$Dx^{a} -> q^{a}-p^{a}$) substitute (tst2,$x^{a} -> p^{a}$) distribute (tst2) sort_product (tst2) rename_dummies (tst2) canonicalise (tst2) # cdb (tst2.202,tst2) substitute (tst3,$Dx^{a} -> q^{a}-p^{a}$) substitute (tst3,$x^{a} -> p^{a}$) distribute (tst3) sort_product (tst3) rename_dummies (tst3) canonicalise (tst3) # cdb (tst3.202,tst3) substitute (tst4,$Dx^{a} -> q^{a}-p^{a}$) substitute (tst4,$x^{a} -> p^{a}$) distribute (tst4) sort_product (tst4) rename_dummies (tst4) canonicalise (tst4) # cdb (tst4.202,tst4) substitute (tst5,$Dx^{a} -> q^{a}-p^{a}$) substitute (tst5,$x^{a} -> p^{a}$) distribute (tst5) sort_product (tst5) rename_dummies (tst5) canonicalise (tst5) # cdb (tst5.202,tst5) \end{cadabra} \clearpage % ================================================================================================= \section*{Reformatting} \begin{cadabra} def truncateR (obj,n): # I would like to assign different weights to \nabla_{a}, \nabla_{a b}, \nabla_{a b c} etc. but no matter # what I do it appears that Cadabra assigns the same weight to all of these regardless of the number of subscripts. # It seems that the weight is assigned to the symbol \nabla alone. So I'm forced to use the following substitution trick. Q_{a b c d}::Weight(label=numR,value=2). Q_{a b c d e}::Weight(label=numR,value=3). Q_{a b c d e f}::Weight(label=numR,value=4). Q_{a b c d e f g}::Weight(label=numR,value=5). tmp := @(obj). substitute (tmp, $\nabla_{e f g}{R_{a b c d}} -> Q_{a b c d e f g}$) substitute (tmp, $\nabla_{e f}{R_{a b c d}} -> Q_{a b c d e f}$) substitute (tmp, $\nabla_{e}{R_{a b c d}} -> Q_{a b c d e}$) substitute (tmp, $R_{a b c d} -> Q_{a b c d}$) ans = Ex(0) for i in range (0,n+1): foo := @(tmp). bah = Ex("numR = " + str(i)) keep_weight (foo, bah) ans = ans + foo substitute (ans, $Q_{a b c d e f g} -> \nabla_{e f g}{R_{a b c d}}$) substitute (ans, $Q_{a b c d e f} -> \nabla_{e f}{R_{a b c d}}$) substitute (ans, $Q_{a b c d e} -> \nabla_{e}{R_{a b c d}}$) substitute (ans, $Q_{a b c d} -> R_{a b c d}$) return ans tst2 = truncateR (tst2,2) # cdb (tst2.301,tst2) tst3 = truncateR (tst3,3) # cdb (tst3.301,tst3) tst4 = truncateR (tst4,4) # cdb (tst4.301,tst4) tst5 = truncateR (tst5,5) # cdb (tst5.301,tst5) \end{cadabra} \clearpage % ================================================================================================= \section*{Errors is mid-point estimates for $L^2_{PQ}$} \begin{dgroup*} \begin{dmath*} \left(L^2_{PQ} - g_{ab}(\bar x) Dx^a Dx^b\right)_2 = \cdb{tst2.301} \end{dmath*} \begin{dmath*} \left(L^2_{PQ} - g_{ab}(\bar x) Dx^a Dx^b\right)_3 = \cdb{tst3.301} \end{dmath*} \begin{dmath*} \left(L^2_{PQ} - g_{ab}(\bar x) Dx^a Dx^b\right)_4 = \cdb{tst4.301} \end{dmath*} \begin{dmath*} \left(L^2_{PQ} - g_{ab}(\bar x) Dx^a Dx^b\right)_5 = \cdb{tst5.301} \end{dmath*} \end{dgroup*} % ================================================================================================= % export checkpoints in json format \bgroup \CdbSetup{action=hide} \begin{cadabra} for i in range( len(checkpoint) ): cdblib.put ('check{:03d}'.format(i),checkpoint[i],checkpoint_file) \end{cadabra} \egroup \end{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Copyright (c) 2003-2018 by The University of Queensland % http://www.uq.edu.au % % Primary Business: Queensland, Australia % Licensed under the Apache License, version 2.0 % http://www.apache.org/licenses/LICENSE-2.0 % % Development until 2012 by Earth Systems Science Computational Center (ESSCC) % Development 2012-2013 by School of Earth Sciences % Development from 2014 by Centre for Geoscience Computing (GeoComp) % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \chapter{The \ripley Module}\label{chap:ripley}\index{ripley} %\declaremodule{extension}{ripley} %\modulesynopsis{Solving linear, steady partial differential equations using finite elements} \ripley is an alternative domain library to \finley; it supports structured, uniform meshes with rectangular elements in 2D and hexahedral elements in 3D. Uniform meshes allow a straightforward division of elements among processes with \MPI and allow for a number of optimizations when solving PDEs. \ripley also supports fast assemblers for certain types of PDE (specifically Lam\'e and Wave PDEs). These assemblers make use of the regular nature of the domain to optimize the stiffness matrix assembly process for these specific problems. Finally, \ripley is currently the only domain family that supports GPU-based solvers. As a result, \ripley domains cannot be created by reading from a mesh file since only one element type is supported and all elements need to be equally sized. For the same reasons, \ripley does not allow assigning coordinates via \function{setX}. While \ripley cannot be used with mesh files, it can be used to read in \GOCAD \index{GOCAD} \index{ripley!GOCAD} data. A script with an example of a voxet reader is included in the examples as \texttt{voxet_reader.py}. Other than use of meshfiles, \ripley and \finley are generally interchangeable in a script with both modules having the \class{Rectangle} or \class{Brick} functions available. Consider the following example which creates a 2D \ripley domain: \begin{python} from esys.ripley import Rectangle, Brick dom = Rectangle(9, 9) \end{python} \index{ripley!multi-resolution domains} \index{multi-resolution domains} Multi-resolution domains are supported in \ripley via \class{MultiBrick} and \class{MultiRectangle}. Each level of one of these domains has twice the elements in each axis of the next lower resolution. The \class{MultiBrick} is not currently supported when running \escript with multiple processes using \MPI. Interpolation between these multi-resolution domains is possible providing they have matching dimensions and subdivisions, along with a compatible number of elements. To simplify these conditions the use of \class{MultiResolutionDomain} is highly recommended. The following example creates two 2D domains of different resolutions and interpolates between them: \begin{python} from esys.ripley import MultiResolutionDomain mrd = MultiResolutionDomain(2, n0=10, n1=10) ten_by_ten = mrd.getLevel(0) data10 = Vector(..., Function(ten_by_ten)) ... forty_by_forty = mrd.getLevel(2) data40 = interpolate(data10, Function(forty_by_forty)) \end{python} \section{Formulation} For a single PDE that has a solution with a single component the linear PDE is defined in the following form: \begin{equation}\label{eq:ripleysingle} \begin{array}{cl} & \displaystyle{ \int_{\Omega} A_{jl} \cdot v_{,j}u_{,l}+ B_{j} \cdot v_{,j} u+ C_{l} \cdot v u_{,l}+D \cdot vu \; d\Omega } + \displaystyle{\int_{\Gamma} d \cdot vu \; d{\Gamma} }\\ = & \displaystyle{\int_{\Omega} X_{j} \cdot v_{,j}+ Y \cdot v \; d\Omega } + \displaystyle{\int_{\Gamma} y \cdot v \; d{\Gamma}} \end{array} \end{equation} \section{Meshes} \label{sec:ripleymeshes} An example 2D mesh from \ripley is shown in Figure~\ref{fig:ripleyrect}. Mesh files cannot be used to generate \ripley domains, i.e. \ripley does not have \function{ReadGmsh} or \function{ReadMesh} functions. Instead, \ripley domains are always created using a call to \function{Brick} or \function{Rectangle}, see Section~\ref{sec:ripleyfuncs}. \begin{figure} \centerline{\includegraphics{RipleyMesh}} \caption{10x10 \ripley Rectangle created with \var{l0=(5.5, 15.5)} and \var{l1=(9.0, 14.0)}} \label{fig:ripleyrect} \end{figure} \section{Functions}\label{sec:ripleyfuncs} \begin{funcdesc}{Brick}{n0,n1,n2,l0=1.,l1=1.,l2=1.,d0=-1,d1=-1,d2=-1, diracPoints=list(), diracTags=list()} generates a \Domain object representing a three-dimensional brick between $(0,0,0)$ and $(l0,l1,l2)$ with orthogonal faces. All elements will be regular. The brick is filled with \var{n0} elements along the $x_0$-axis, \var{n1} elements along the $x_1$-axis and \var{n2} elements along the $x_2$-axis. If built with \MPI support, the domain will be subdivided \var{d0} times along the $x_0$-axis, \var{d1} times along the $x_1$-axis, and \var{d2} times along the $x_2$-axis. \var{d0}, \var{d1}, and \var{d2} must be factors of the number of \MPI processes requested. If axial subdivisions are not specified, automatic domain subdivision will take place. This may not be the most efficient construction and will likely result in extra elements being added to ensure proper distribution of work. Any extra elements added in this way will change the length of the domain proportionately. \var{diracPoints} is a list of coordinate-tuples of points within the mesh, each point tagged with the respective string within \var{diracTags}. \end{funcdesc} \begin{funcdesc}{Rectangle}{n0,n1,l0=1.,l1=1.,d0=-1,d1=-1, diracPoints=list(), diracTags=list()} generates a \Domain object representing a two-dimensional rectangle between $(0,0)$ and $(l0,l1)$ with orthogonal faces. All elements will be regular. The rectangle is filled with \var{n0} elements along the $x_0$-axis and \var{n1} elements along the $x_1$-axis. If built with \MPI support, the domain will be subdivided \var{d0} times along the $x_0$-axis and \var{d1} times along the $x_1$-axis. \var{d0} and \var{d1} must be factors of the number of \MPI processes requested. If axial subdivisions are not specified, automatic domain subdivision will take place. This may not be the most efficient construction and will likely result in extra elements being added to ensure proper distribution of work. Any extra elements added in this way will change the length of the domain proportionately. \var{diracPoints} is a list of coordinate-tuples of points within the mesh, each point tagged with the respective string within \var{diracTags}. \end{funcdesc} \noindent The arguments \var{l0}, \var{l1} and \var{l2} for \function{Brick} and \function{Rectangle} may also be given as tuples \var{(x0,x1)} in which case the coordinates will range between \var{x0} and \var{x1}. For example: \begin{python} from esys.ripley import Rectangle dom = Rectangle(10, 10, l0=(5.5, 15.5), l1=(9.0, 14.0)) \end{python} \noindent This will create a rectangle with $10$ by $10$ elements where the bottom-left node is located at $(5.5, 9.0)$ and the top-right node has coordinates $(15.5, 14.0)$, see Figure~\ref{fig:ripleyrect}. The \class{MultiResolutionDomain} class is available as a wrapper, taking the dimension of the domain followed by the same arguments as \class{Brick} (if a two-dimensional domain is requested, any extra arguments over those used by \class{Rectangle} are ignored). All of these standard arguments to \class{MultiResolutionDomain} must be supplied as keyword arguments (e.g. \var{d0}=...). The \class{MultiResolutionDomain} can then generate compatible domains for interpolation. \section{Linear Solvers in \SolverOptions} Currently direct solvers and GPU-based solvers are not supported under \MPI when running with more than one rank. By default, \ripley uses the iterative solvers \PCG for symmetric and \BiCGStab for non-symmetric problems. A GPU will not be used unless explicitly requested via the \function{setSolverTarget} method of the solver options. These solvers are only available if \ripley was built with \CUDA support. If the direct solver is selected, which can be useful when solving very ill-posed equations, \ripley uses the \MKL\footnote{If the stiffness matrix is non-regular \MKL may return without a proper error code. If you observe suspicious solutions when using \MKL, this may be caused by a non-invertible operator.} solver package. If \MKL is not available \UMFPACK is used. If \UMFPACK is not available a suitable iterative solver from \PASO is used, but if a direct solver was requested via \SolverOptions an exception will be raised.
\section{Exchange rates}
% LaTeX resume using res.cls \documentclass[line,margin]{res} %\usepackage{helvetica} % uses helvetica postscript font (download helvetica.sty) %\usepackage{newcent} % uses new century schoolbook postscript font \begin{document} \name{Susan R. Bumpershoot} % \address used twice to have two lines of address \address{1985 Storm Lane, Troy, NY 12180} \address{(518) 273-0014 or (518) 272-6666} \begin{resume} \section{OBJECTIVE} A position in the field of computers with special interests in business applications programming, information processing, and management systems. \section{EDUCATION} {\sl Bachelor of Science,} Interdisciplinary Science \\ % \sl will be bold italic in New Century Schoolbook (or % any postscript font) and just slanted in % Computer Modern (default) font Rensselaer Polytechnic Institute, Troy, NY, expected December 1990 \\ Concentration: Computer Science \\ Minor: Management \section{COMPUTER \\ SKILLS} {\sl Languages \& Software:} COBOL, IFPS, Focus, Megacalc, Pascal, Modula2, C, APL, SNOBOL, FORTRAN, LISP, SPIRES, BASIC, VSPC Autotab, IBM 370 Assembler, Lotus 1-2-3. \\ {\sl Operating Systems:} MTS, TSO, Unix. \section{EXPERIENCE} {\sl Business Applications Programmer} \hfill Fall 1990 \\ Allied-Signal Bendix Friction Materials Division, Financial Planning Department, Latham, NY \begin{itemize} \itemsep -2pt % reduce space between items \item Developed four "user friendly" forecasting systems each of which produces 18 to 139 individual reports. \item Developed or improved almost all IFPS programs used for financial reports. \end{itemize} {\sl Research Programmer} \hfill Summer 1990 \\ Psychology Department, Rensselaer Polytechnic Institute \begin{itemize} \itemsep -2pt %reduce space between items \item Performed computer aided statistical analysis of data. \end{itemize} {\sl Assistant Manager} \hfill Summers 1988-89 \\ Thunder Restaurant, Canton, CT \begin{itemize} \item Recognized need for, developed, and wrote employee training manual. Performed various duties including cooking, employee training, ordering, and inventory control. \end{itemize} \section{COMMUNITY \\ SERVICE} Organized and directed the 1988 and 1989 Grand Marshall Week \newline ``Basketball Marathon.'' A 24 hour charity event to benefit the Troy Boys Club. Over 250 people participated each year. \section{EXTRA-CURRICULAR \\ ACTIVITIES} Elected {\it House Manager}, Rho Phi Sorority \\ Elected {\it Sports Chairman} \\ Attended Krannet Leadership Conference \\ Headed delegation to Rho Phi Congress \\ Junior varsity basketball team \\ Participant, seven intramural athletic teams \end{resume} \end{document}
% This is our submission, modified from: % the file JFP2egui.lhs % release v1.02, 27th September 2001 % (based on JFPguide.lhs v1.11 for LaLhs 2.09) % Copyright (C) 2001 Cambridge University Press \NeedsTeXFormat{LaTeX2e} \documentclass{jfp1} %%% Macros for the guide only %%% %\providecommand\AMSLaTeX{AMS\,\LaTeX} %\newcommand\eg{\emph{e.g.}\ } %\newcommand\etc{\emph{etc.}} %\newcommand\bcmdtab{\noindent\bgroup\tabcolsep=0pt% % \begin{tabular}{@{}p{10pc}@{}p{20pc}@{}}} %\newcommand\ecmdtab{\end{tabular}\egroup} %\newcommand\rch[1]{$\longrightarrow\rlap{$#1$}$\hspace{1em}} %\newcommand\lra{\ensuremath{\quad\longrightarrow\quad}} \jdate{August 2017} \pubyear{2017} \pagerange{\pageref{firstpage}--\pageref{lastpage}} \doi{...} %\newtheorem{lemma}{Lemma}[section] \input{lhs2TeXSafeCommands} \input{prelude} \title{Arrows for Parallel Computation} \ifthenelse{\boolean{anonymous}}{% \author{Submission ID xxxxxx} }{% %\author{Martin Braun, Phil Trinder, and Oleg Lobachev} %\affiliation{University Bayreuth, Germany and Glasgow University, UK} \author[M. Braun, O. Lobachev, and P. Trinder]% {\textls*{MARTIN BRAUN}\\ University Bayreuth, 95440 Bayreuth, Germany\\ \textls*{OLEG LOBACHEV}\\ University Bayreuth, 95440 Bayreuth, Germany\\ \and\ \textls*{PHIL TRINDER}\\ Glasgow University, Glasgow, G12 8QQ, Scotland} }% end ifthenelse \begin{document} \label{firstpage} \def\SymbReg{\textsuperscript{\textregistered}} \maketitle %% environment inside \input{abstract.tex} \tableofcontents % %%include abstract.lhs % %\newpage %\pagebreak \input{motivation} \input{relwork} %\begin{flushright} % %\end{flushright} \section{Background} \label{sec:background} This section gives a short overview of Arrows (Section~\ref{sec:arrows}) and of GpH, the |Par| Monad, and Eden, the three parallel Haskells which we base our DSL on (Section~\ref{sec:parallelHaskells}). \input{arrows} \input{parallelHaskells} %\pagebreak %\pagebreak %\pagebreak \input{parrows} %\pagebreak \input{basicSkeletons} %\pagebreak \input{syntacticSugar} %\pagebreak \input{futures} %\pagebreak \input{mapSkeletons} %\pagebreak \input{topologySkeletons} %\pagebreak \input{benchmarks} %%\pagebreak \input{conclusion} %\pagebreak \bibliographystyle{jfp} \bibliography{references,main} \appendix \input{utilityFunctions} \end{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % THE CASANOVA LANGUAGE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% In this section we present the Casanova language syntax, typing rules and semantics. Before we start, we will give a general idea of how the language works with a small example. We will build a very simple game where asteroids enter the screen from the top, scroll down to the bottom at different velocities and then disappear. \begin{center} \line(1,0){240} \end{center} \textit{Note on syntactic sugar:} We will use the following syntactic sugar to increase source code readability: Rather than write: \begin{lstlisting} let! _ = b1 in b2 \end{lstlisting} we can write: \begin{lstlisting} do! b1 in b2 \end{lstlisting} Rather than write: \begin{lstlisting} let x = t1 in let y = t2 in t3 \end{lstlisting} we can write: \begin{lstlisting} let x = t1 let y = t2 t3 \end{lstlisting} \begin{comment} We may also directly iterate all the elements of a table \texttt{t} by writing: \begin{lstlisting} for x in t do action \end{lstlisting} rather than explicitly using indices or \texttt{head} and \texttt{tail}. \end{comment} \begin{center} \line(1,0){240} \end{center} A Casanova program is composed of two portions: \begin{itemize} \item the state of the game, a series of types arranged hierarchically (typically at least one for the global state and one for the state of each entity); each portion of the game state may contain exactly one rule \item the main behavior, which is performs a series of instructions on all the mutable fields of the state (those marked as \texttt{Rule T} or \texttt{Ref T}; behavior execution is suspended at the \texttt{yield} statement, and resumed at the next tick \end{itemize} The state of our simple program is defined as: \begin{lstlisting} type Asteroid = { Y : Rule float :: \(self,dt) -> self.Y + dt * self.VelY VelY : float X : float } type GameState = { Asteroids : Rule(Table Asteroid) :: \state -> [a | a <- !state.Asteroids && a.Y > 0] DestroyedAsteroids : Rule<int> :: \state -> !self.DestroyedAsteroids + count([a | a <- !state.Asteroids && a.Y <= 0]) } \end{lstlisting} In a type declaration, the \texttt{:} operator means ``has type'', while the \texttt{::} operator means ``has rule''. Rules can access the game state, the current entity and the time delta between the current and previous ticks. In the state definition above we can see that the state is comprised by a set of asteroids which are removed when they reach the bottom. Removing these asteroids increments a counter, which is essentially the ``score'' of our pseudo-game. Each asteroid moves in the direction of its velocity. The initial state is then provided: \begin{lstlisting} let state0 = { Asteroids = [] DestroyedAsteroids = 0 } \end{lstlisting} After defining the state we must give an initial behavior. As can be easily noticed, our game does not generate any asteroids and so the initial state will never change. Since creating asteroids is an activity that certainly must not be performed at every tick (otherwise we could generate in excess of 60 asteroids per second: clearly too many), we need a function that is capable of performing \textit{different} operations on the state depending on time. Since rules perform the \textit{same} operation at every tick, they are unsuited to this kind of processing. Behaviors are built exactly around this need. The behavior for our game is the following: \begin{lstlisting} let main state = let random = mk_random() let rec wait interval = { let! t0 = time do! yield let! t = time let dt = t - t0 if dt > interval then return () else do! wait (interval - dt) } let rec behavior() = { do! wait (random.Next(1,3)) do! state.Asteroids.Add { X = random.Next(-1,+1) Y = 1 VelY = random.Next(-0.1,-0.2) } if state.DestroyedAsteroids < 100 then do! behavior() else return () } in behavior() \end{lstlisting} Our behavior declares a random number generator and then starts iterating a function that waits between 1 and 3 seconds and then creates a random asteroid. When the number of destroyed asteroids is greater than 100, the function stops and the game ends (games end when their main behavior terminates). Notice that behaviors are expressed with two different syntaxes: an ML-style syntax for pure terms (those which read the state and simply perform computations) and an imperative-style syntax for impure terms (those which write the state and interact with time such as wait). The imperative syntax loosely follows the monadic syntax of the F\# language, where a monadic block is declared within \texttt{\{\}} parentheses, monadic operations are preceded by either \texttt{do!} or \texttt{let!} and returning a result is done with the \texttt{return} statement. \subsection{Syntax} In the remainder of this section we will adopt the following conventions: \begin{itemize} \item capitalized items such as \texttt{Program} and \texttt{StateDef} are grammatical elements \item quoted items such as \texttt{`type'} and \texttt{`GameState'} are keywords that must appear as indicated \item items surrounded by \texttt{[ ]} parentheses such as \texttt{[EntityName]} are user-defined strings \end{itemize} The program syntax starts with the definition of the state (a series of type definitions with rules) and is followed by the entry point (the initial state and the initial behavior): \begin{lstlisting} Program ::= StateDef Main StateDef ::= EntityDefs \end{lstlisting} A type definition is comprised of one of various primitive types such as integers, floating point numbers, two- or three- dimensional vectors, etc. combined into any of the usual composite types known to functional programmers such as tuples, functions, records and sum types. Also, type declarations may contain a rule (which is simply a term, even though with the limitation that only pure functional terms are allowed inside rules): \begin{lstlisting} TypeDef ::= TypeDef' | TypeDef' :: Rule TypeDef' ::= `()' | `int' | `float' | `Vector2' | ... | TypeDef $\times$ TypeDef | TypeDef $\rightarrow$ TypeDef | `{' Labels `}' | TypeDef $+$ TypeDef | Modifier TypeDef | [EntityName] Labels ::= Label; Labels | Label Label ::= [Name] `:' TypeDef Rule ::= Term \end{lstlisting} A \texttt{Modifier} for a type definition allows to make a field mutable (\texttt{Rule} or \texttt{Ref}), or to use queries to manipulate that field (\texttt{Table}). Also, another important modifier is \texttt{Foreign} which can be seen as a programmer annotation that tells the compiler how a certain field is just a pointer to another portion of the state and as such it must not be processed recursively: \begin{lstlisting} Modifier ::= Rule | Ref | Table | Foreign \end{lstlisting} Entities are definied as a series of type definitions with a name which can be referenced anywhere in the state; the last entity to be defined is the game state itself: \begin{lstlisting} EntityDefs ::= `type' `GameState' = TypeDef | EntityDef EntityDefs EntityDef ::= `type' [EntityName] `=' TypeDef \end{lstlisting} The various entity names are simply replaced with their type definition in the remainder of the program, according to the $\llbracket \bullet \rrbracket_{\mathtt{MAIN}}$ translation rule: \begin{mathpar} \llbracket \mathtt{type\ EntityName\ =\ TypeDef;\ EntityDefs; Main} \rrbracket_{\mathtt{MAIN}} = \llbracket \mathtt{EntityDefs; \ Main} \rrbracket_{\mathtt{MAIN}} \mathtt{[EntityName} \mapsto \mathtt{TypeDef]} \and \llbracket \mathtt{TypeDef;\ Main} \rrbracket_{\mathtt{MAIN}} = \mathtt{TypeDef;\ Main} \end{mathpar} The actual type definition of the state may be extracted from the program with the $\llbracket \bullet \rrbracket_{\mathtt{STATE}}$ transformation, which extracts the type definition and erases all the rules from it; this means that two entities may have the same type with different sets of rules. The $\llbracket \bullet \rrbracket_{\mathtt{STATE}}$ transformation inductively removes all rules from a type declaration: \begin{mathpar} \llbracket T \mathtt{:: Rule} \rrbracket_{\mathtt{STATE}} = \llbracket T \rrbracket_{\mathtt{STATE}} \and \llbracket T_1 \times T_2 \rrbracket_{\mathtt{STATE}} = \llbracket T_1 \rrbracket_{\mathtt{STATE}} \times \llbracket T_2 \rrbracket_{\mathtt{STATE}} \and \llbracket T_1 + T_2 \rrbracket_{\mathtt{STATE}} = \llbracket T_1 \rrbracket_{\mathtt{STATE}} + \llbracket T_2 \rrbracket_{\mathtt{STATE}} \and \\ (...) \\ \end{mathpar} A term can be a simple, ML-style functional term (we do not give all these possible definitions because they are fairly known [ML syntax and types]) or an imperative behavior. Functional terms can read references with the \texttt{!} operator and can use a Haskell-style table-comprehension syntax: \begin{lstlisting} Term ::= `let' [Var] `=' Term `in' Term | `if' Term `then' Term `else' Term | Term Term | !Term | ... (* other ML-style terms: fun, types, head, tail for tables, etc. *) | [ Term | Predicates ] | `{' Behavior `}' Predicates ::= $\epsilon$ | [Var] `<-' Term, Predicates | Term, Predicates \end{lstlisting} A behavior defines an imperative coroutine that is capable of reading and writing the state and manipulating time. Behaviors can be freely mixed with terms. The simplest behavior simply returns a result with \texttt{return}. The result of a behavior can be plugged inside another behavior with \texttt{let!}, which behaves like a monadic binding operator. A reference can be assigned inside a behavior with \texttt{:=}; a behavior can suspend itself until the next tick (\texttt{yield}) and it may read the current time with \texttt{time}. Behaviors can be combined into more complex behaviors with a small set of combinators. A behavior may spawn another behavior with \texttt{run}, be executed in parallel with another behavior with $\vee$ or $\wedge$, be suspended until another behavior completes ($\Rightarrow$), be repeated indefinitely (\texttt{repeat}) and be forced to execute in a single tick (\texttt{atomic}): \begin{lstlisting} Behavior ::= `return' Term | `let!' [Var] `=' Term `in' Term | Term := Term | `yield' | `time' | `run' Term | Term $\vee$ Term | Term $\wedge$ Term | Term $\Rightarrow$ Term | `repeat' Term | `atomic' Term \end{lstlisting} The main program is comprised of two terms: the initial state and the initial behavior: \begin{lstlisting} Main ::= `let' state0 = Term `let' main = Term \end{lstlisting} \subsection{Type System} Our language is strongly typed. We will omit some type declarations when obvious, and our language will make use of type inference. Typing rules for ML-style terms are the usual ML-style typing rules [ML syntax and types]; for example: \begin{mathpar} \inferrule {\Gamma \vdash t_1:U \\\\ \Gamma,x:U \vdash t_2 : V} {\Gamma \vdash \mathtt{let}\ x \mathtt{ = } t_1\ \mathtt{in}\ t_2\ :V} \quad \textsc {LET} \and \inferrule {\Gamma \vdash c:bool \\\\ \Gamma \vdash t_1 : T \\\\ \Gamma \vdash t_2 : T} {\Gamma \vdash \mathtt{if}\ c\ \mathtt{then}\ t_1\ \mathtt{else}\ t_2 : T} \quad \textsc {IF} \and \inferrule {\Gamma \vdash r:Ref\ T} {\Gamma \vdash !r : T} \quad \textsc {REF-GET} \and \inferrule {\Gamma \vdash r:Rule\ T} {\Gamma \vdash !r : T} \quad \textsc {RULE-GET} \and \\ (...) \end{mathpar} Table comprehensions are types thusly: \begin{mathpar} \inferrule {\mathtt{decls(} \Gamma \mathtt{,ts)} \vdash t_1:T} {\Gamma \vdash \mathtt{[}\ t_1\ \mathtt{|}\ t_s\ \mathtt{]}\ :Table\ T} \quad \textsc {TABLE} \and \mathtt{decls(} \Gamma \mathtt{,} \epsilon \mathtt{)} = \Gamma \and \inferrule {\Gamma \vdash t:Table\ T} {\mathtt{decls(} \Gamma \mathtt{,(x} \leftarrow \mathtt{t, ts))} = \mathtt{decls((} \Gamma \mathtt{,x:T),ts)}} \and \inferrule {\Gamma \vdash t:bool} {\mathtt{decls(} \Gamma \mathtt{,(t, ts))} = \mathtt{decls(} \Gamma \mathtt{,ts)}} \and \\ (...) \end{mathpar} Terms cannot have types with rules in them, that is rules can only be used in the top-level state definition. We will use the above notation for typing rules, where to be more precise we should have written $\llbracket T \rrbracket_{\mathtt{STATE}}$ instead of simply \texttt{T} for each type to make sure that rules do not appear in a type annotation inside a term. We also state another informal restriction, that is function types may not have rules; so, a type such as $(U :: Rule) \rightarrow V$ is forbidden and generates a compile-time error. We introduce another type, \texttt{Behavior T}, which allows us to type behaviors. Instances of \texttt{Behavior} can be constructed but never eliminated within a program: behaviors are eliminated implicitly inside the semantics. The first typing rules for behaviors are the monadic typing rules which allow to build and consume basic behaviors: \begin{mathpar} \inferrule {\Gamma \vdash x:T} {\Gamma \vdash \mathtt{return}\ x :Behavior\ T} \quad \textsc {RETURN} \and \inferrule {\Gamma \vdash t_1 : Behavior\ U \\\\ \Gamma,x:U \vdash t_2 : Behavior\ V} {\Gamma \vdash \mathtt{let!}\ x\ \mathtt{=}\ t_1\ \mathtt{in}\ t_2 : Behavior\ V} \quad \textsc {BIND} \end{mathpar} Behaviors may also be suspended for a tick (to wait for an application of all rules or to synchronize between behaviors, for example), they may read the current time (in fractional seconds) or they may spawn other behaviors: \begin{mathpar} \inferrule {\\} {\mathtt{yield} : Behavior\ ()} \quad \textsc {YIELD} \and \inferrule {\\} {\mathtt{time} : Behavior\ float} \quad \textsc {TIME} \and \inferrule {\Gamma \vdash t : Behavior\ ()} {\Gamma \vdash \mathtt{run}\ t : Behavior\ ()} \quad \textsc {RUN} \end{mathpar} Behaviors are the only places where unrestricted assignment of the state may happen; behaviors may indiscriminately write any portion of the state: \begin{mathpar} \inferrule {\Gamma \vdash t_1 : Ref\ U \\\\ \Gamma \vdash t_2 : U} {\Gamma t_1 \mathtt{:=} t_2 : Behavior\ ()} \quad \textsc {REF-SET} \and \inferrule {\Gamma \vdash t_1 : Rule\ U \\\\ \Gamma \vdash t_2 : U} {\Gamma t_1 \mathtt{:=} t_2 : Behavior\ ()} \quad \textsc {RULE-SET} \end{mathpar} We also support a small behavior calculus. Two behaviors may be executed concurrently (the first one that terminates returns its result while the other behavior is discarded), or they may be executed in parallel (when both terminate their results are returned together). A behavior may also act as a guard for another behavior, that is until the first behavior does not terminate with a result the second behavior is kept waiting. Finally, a behavior may be repeated indefinitely or it may be forced to run inside a single tick: \begin{mathpar} \inferrule {\Gamma \vdash t_1 : Behavior\ U \\\\ \Gamma \vdash t_2 : Behavior\ V} {\Gamma t_1 \vee t_2 : Behavior\ (U + V)} \quad \textsc {CONCURRENT} \and \inferrule {\Gamma \vdash t_1 : Behavior\ U \\\\ \Gamma \vdash t_2 : Behavior\ V} {\Gamma t_1 \wedge t_2 : Behavior\ (U \times V)} \quad \textsc {PARALLEL} \and \inferrule {\Gamma \vdash t_1 : Behavior\ (U + ()) \\\\ \Gamma \vdash t_2 : U \rightarrow Behavior\ V} {\Gamma t_1 \Rightarrow t_2 : Behavior\ V} \quad \textsc {GUARD} \and \inferrule {\Gamma \vdash t : Behavior\ ()} {\Gamma \vdash \mathtt{repeat}\ t : Behavior\ ()} \quad \textsc {REPEAT} \and \inferrule {\Gamma \vdash t : Behavior\ ()} {\Gamma \vdash \mathtt{atomic}\ t : Behavior\ ()} \quad \textsc {ATOMIC} \end{mathpar} The inability to eliminate a behavior unless inside another behavior is important because it allows us to force rules to not contain behaviors; thanks to this limitation we can ensure that the execution of rules may only read from the state and never write to it, and so rules can be made to behave as if they are executed simultaneously without risking complex interdependencies. This simplifies many instances of game programming; for example, consider the rules seen in the example at the beginning of the section: \begin{lstlisting} Asteroids : Rule(Table Asteroid) :: \state -> [a | a <- !state.Asteroids && a.Y > 0] DestroyedAsteroids : Rule<int> :: \state -> !self.DestroyedAsteroids + count([a | a <- !state.Asteroids && a.Y <= 0]) \end{lstlisting} If rules are executed sequentially from top to bottom, then when an asteroid is eliminated then that same asteroid will not be available anymore when computing the sum of asteroids waiting for deletion. Types are used for restricting rules. In particular, inside the definition of an entity \texttt{type EntityName = TypeDef}, all its rules must have type (given that the rule has type \texttt{Rule T}): \begin{lstlisting} GameState $\times$ EntityName $\times$ float $\rightarrow$ T \end{lstlisting} For convenience any subset of \texttt{GameState, EntityName, float} may be used in practice. The final restrictions limit the acceptable terms for the \texttt{Main} program; the program is defined as: \begin{lstlisting} StateDefinition let state0 = $t_1$ let main = $t_2$ \end{lstlisting} and we require that $t_1$ must have type: $$\llbracket \mathtt{StateTypeDefinition} \rrbracket_{\mathtt{STATE}}$$ and $t_2$ must have type: $$\llbracket \mathtt{StateTypeDefinition} \rrbracket_{\mathtt{STATE}} \rightarrow \ \mathtt{Behavior\ ()}$$ where \begin{mathpar} \mathtt{(StateTypeDefinition;\ Main)} = \llbracket (StateDefinition; \mathtt{let\ state0 = ...}) \rrbracket_{\mathtt{MAIN}} \end{mathpar} \subsection{Semantics} Rule semantics (->, =>), everywhere function, script semantics.
% % This is the LaTeX template file for lecture notes for CS294-8, % Computational Biology for Computer Scientists. When preparing % LaTeX notes for this class, please use this template. % % To familiarize yourself with this template, the body contains % some examples of its use. Look them over. Then you can % run LaTeX on this file. After you have LaTeXed this file then % you can look over the result either by printing it out with % dvips or using xdvi. % % This template is based on the template for Prof. Sinclair's CS 270. \documentclass[11pt, twosides]{article} \usepackage[utf8]{inputenc} \usepackage{graphicx} \usepackage{graphics} \usepackage{amsmath} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsthm} \usepackage{xcolor} \setlength{\oddsidemargin}{0.25 in} \setlength{\evensidemargin}{-0.25 in} \setlength{\topmargin}{-0.6 in} \setlength{\textwidth}{6.5 in} \setlength{\textheight}{8.5 in} \setlength{\headsep}{0.75 in} \setlength{\parindent}{0 in} \setlength{\parskip}{0.1 in} % % The following commands set up the lecnum (lecture number) % counter and make various numbering schemes work relative % to the lecture number. % \newcounter{lecnum} \renewcommand{\thepage}{\thelecnum-\arabic{page}} \renewcommand{\thesection}{\thelecnum.\arabic{section}} \renewcommand{\theequation}{\thelecnum.\arabic{equation}} \renewcommand{\thefigure}{\thelecnum.\arabic{figure}} \renewcommand{\thetable}{\thelecnum.\arabic{table}} % % The following macro is used to generate the header. % \newcommand{\lecture}[4]{ % \pagestyle{myheadings} \thispagestyle{plain} \newpage \setcounter{lecnum}{#1} \setcounter{page}{1} \noindent \begin{center} \framebox{ \vbox{\vspace{2mm} \hbox to 6.28in { {\bf CS 419M Introduction to Machine Learning \hfill Spring 2021-22} } \vspace{4mm} \hbox to 6.28in { {\Large \hfill Lecture #1: #2 \hfill} } \vspace{2mm} \hbox to 6.28in { {\it Lecturer: #3 \hfill Scribe: #4} } \vspace{2mm}} } \end{center} \markboth{Lecture #1: #2}{Lecture #1: #2} } % % Convention for citations is authors' initials followed by the year. % For example, to cite a paper by Leighton and Maggs you would type % \cite{LM89}, and to cite a paper by Strassen you would type \cite{S69}. % (To avoid bibliography problems, for now we redefine the \cite command.) % Also commands that create a suitable format for the reference list. % \renewcommand{\cite}[1]{[#1]} % \def\beginrefs{\begin{list}% % {[\arabic{equation}]}{\usecounter{equation} % \setlength{\leftmargin}{2.0truecm}\setlength{\labelsep}{0.4truecm}% % \setlength{\labelwidth}{1.6truecm}}} % \def\endrefs{\end{list}} % \def\bibentry#1{\item[\hbox{[#1]}]} %Use this command for a figure; it puts a figure in wherever you want it. %usage: \fig{NUMBER}{SPACE-IN-INCHES}{CAPTION} % \newcommand{\fig}[3]{ % \vspace{#2} % \begin{center} % Figure \thelecnum.#1:~#3 % \end{center} % } % Use these for theorems, lemmas, proofs, etc. \newtheorem{theorem}{Theorem}[lecnum] \newtheorem{lemma}[theorem]{Lemma} \newtheorem{proposition}[theorem]{Proposition} \newtheorem{claim}[theorem]{Claim} \newtheorem{corollary}[theorem]{Corollary} \newtheorem{definition}[theorem]{Definition} % \newenvironment{proof}{{\bf Proof:}}{\hfill\rule{2mm}{2mm}} % **** IF YOU WANT TO DEFINE ADDITIONAL MACROS FOR YOURSELF, PUT THEM HERE: \begin{document} %FILL IN THE RIGHT INFO. %\lecture{**LECTURE-NUMBER**}{**DATE**}{**LECTURER**}{**SCRIBE**} \lecture{10}{Regression Loss Function Duality}{Abir De}{Group 2} %\lecture{x}{Title}{Abir De}{Group y} \section{Recap} \subsection{Why is Bias Term not Regularised?} For the loss function given as \begin{eqnarray*} F_{D}(W) &=& \Sigma_{i\in D}[l(w^Tx_i+b,y_i)+\lambda||w||^2] \end{eqnarray*} Bias term b is usually not regularised. This gives a default value of prediction when no data is provided for training the model. If the loss function is not regularised with respect to bias term, the loss function not stable, As the minimum of the eigenvalue of hessian of loss function is 0. Meaning the loss function is not strictly convex. \begin{eqnarray*} min\ eig \left( \frac{\partial^2 F}{\partial b^2} \right) = 0 \Rightarrow F(w,b) \ is \ not \ strictly \ convex \end{eqnarray*} \section{Regression Dual Formulation} Optimization model for support vector machine \begin{eqnarray*} \underset{w,b}{min} \ \ ||w||^2 + C\Sigma_{i\in D}[1-(w^Tx_i+b)y_i)]\ , \ where \ C = \frac{1}{\lambda} \end{eqnarray*} can be equivalently written in the form $$\underset{w,b,\zeta_i \geq 0}{min} \ ||w||^2 + \underset{i\in D}{\Sigma}C \zeta_i $$ $$y_i(w^Tx_i+b)\geq 1-\zeta_i \ \ \forall \ i\in D$$ This problem in constrained space can be converted to unconstrained dual, which is given as\\ $$ \underset{\alpha_i \geq 0, \beta_i \geq 0}{max} \ \underset{w,b,\zeta \geq 0}{min} \ \ ||w||^2+ \underset{i\in D}{\Sigma} \left[ C\zeta_i +\alpha_i(1-\zeta_i-y_i(w^Tx_i+b))-\beta_i\zeta_i\right]$$ \section{Simplifying Dual Equation} Take $F_{w,b,\zeta} = ||w||^2+ \underset{i\in D}{\Sigma} \left[ C\zeta_i +\alpha_i(1-\zeta_i-y_i(w^Tx_i+b))-\beta_i\zeta_i\right]$ Now, $$\frac{\partial F_{w,b,\zeta}}{\partial w} = 2w - y_{i}\underset{i\in D}{\Sigma}x_{i}\alpha_{i} = 0 $$ $$ w = \frac{\underset{i\in D}{\Sigma}x_{i}\alpha_{i}y_{i}}{2} \hspace{1em}.....(i)$$ $$ \frac{\partial F_{w,b,\zeta}}{\partial b} = 0 \Rightarrow \underset{i\in D}{\Sigma}\alpha_{i}y_{i} = 0 \hspace{1em}.....(ii)$$ $$ \frac{\partial F_{w,b,\zeta}}{\partial \zeta} = 0 \Rightarrow c-\alpha_{i}-\beta{i} = 0 $$ $$ \alpha_{i}+\beta{i}=c \hspace{1em}.....(iii) $$ Putting these relations, above dual equation becomes: $$ \underset{\alpha_i \geq 0}{max} \ \ \underset{i\in D}{\Sigma} \alpha_{i} - \frac{1}{4} \underset{i\in D , j\in D}{\Sigma}\alpha_{i}\alpha_{j}x_{i}^{T}x_{j}y_{i}y_{j} $$ $\underset{i\in D}{\Sigma} \alpha_{i} - \frac{1}{4} \underset{i\in D , j\in D}{\Sigma}\alpha_{i}\alpha_{j}x_{i}^{T}x_{j}y_{i}y_{j}$ is concave. And as $\alpha_{i}+\beta{i}=c$ and $\beta_{i}\geq0$, so $0\leq\alpha_{i}\leq c$ \section{Applying Constainsts and Conditions} From Slatu's condition, following two conditions must be satisfied: \begin{equation} \alpha_{i}( (w^T x_{i} + b)y_{i}-1+\zeta_{i}) =0 \end{equation} \begin{equation} \beta_{i}\zeta_{i} = 0 \end{equation} Let's consider some cases: \\ (i) $y_{i}(w^T x_{i} + b)>1$ for some $(x_{i},y_{i}), \alpha_{i}=?$ \\ Ans. As $\beta_{i}\geq0 \ \Rightarrow \ \zeta_{i}=0 \ \Rightarrow \ \alpha_{i}=0$ (ii) $y_{i}(w^T x_{i} + b)<1$ for some $(x_{i},y_{i}), \alpha_{i}=?$ \\ Ans. As $\zeta_{i}>0$ (from $eq^n$ 10.1) $ \ \Rightarrow \ \beta_{i}=0 $ (from $eq^n$ 10.2) $ \Rightarrow \ \alpha_{i}=c $ (as $\alpha_{i}+\beta_{i}=c$) (iii) $y_{i}(w^T x_{i} + b)=1$ for some $(x_{i},y_{i}), \alpha_{i}=?$ \\ Ans. As $ \alpha_{i}\zeta_{i}=0 $ (from $eq^n$ 10.1) $ \ \Rightarrow \ \zeta_{i}=0 $ (using $eq^n$ 10.2) \& As $ \beta_{i}\geq0 \ \Rightarrow \ 0<\alpha\leq c $ (as $\alpha_{i}+\beta_{i}=c$) \section{Group Details and Individual Contribution} % Fill this part \begin{itemize} \item 200020112 Sahil Khan \item 190040120 Sumeet Ranjan \item 200040038 Chaitanya Langde \item 19B080018 Prateek Kumar \end{itemize} \end{document}
% Copyright 2018 by Till Tantau % % This file may be distributed and/or modified % % 1. under the LaTeX Project Public License and/or % 2. under the GNU Free Documentation License. % % See the file doc/generic/pgf/licenses/LICENSE for more details. \section{The Soft Path Subsystem} \label{section-soft-paths} \makeatletter This section describes a set of commands for creating \emph{soft paths} as opposed to the commands of the previous section, which created \emph{hard paths}. A soft path is a path that can still be ``changed'' or ``molded''. Once you (or the \pgfname\ system) is satisfied with a soft path, it is turned into a hard path, which can be inserted into the resulting |.pdf| or |.ps| file. Note that the commands described in this section are ``high-level'' in the sense that they are not implemented in driver files, but rather directly by the \pgfname-system layer. For this reason, the commands for creating soft paths do not start with |\pgfsys@|, but rather with |\pgfsyssoftpath@|. On the other hand, as a user you will never use these commands directly, they are described as part of the low-level interface. \subsection{Path Creation Process} When the user writes a command like |\draw (0bp,0bp) -- (10bp,0bp);| quite a lot happens behind the scenes: % \begin{enumerate} \item The frontend command is translated by \tikzname\ into commands of the basic layer. In essence, the command is translated to something like % \begin{codeexample}[code only] \pgfpathmoveto{\pgfpoint{0bp}{0bp}} \pgfpathlineto{\pgfpoint{10bp}{0bp}} \pgfusepath{stroke} \end{codeexample} % \item The |\pgfpathxxxx| commands do \emph{not} directly call ``hard'' commands like |\pgfsys@xxxx|. Instead, the command |\pgfpathmoveto| invokes a special command called |\pgfsyssoftpath@moveto| and |\pgfpathlineto| invokes |\pgfsyssoftpath@lineto|. The |\pgfsyssoftpath@xxxx| commands, which are described below, construct a soft path. Each time such a command is used, special tokens are added to the end of an internal macro that stores the soft path currently being constructed. \item When the |\pgfusepath| is encountered, the soft path stored in the internal macro is ``invoked''. Only now does a special macro iterate over the soft path. For each line-to or move-to operation on this path it calls an appropriate |\pgfsys@moveto| or |\pgfsys@lineto| in order to, finally, create the desired hard path, namely, the string of literals in the |.pdf| or |.ps| file. \item After the path has been invoked, |\pgfsys@stroke| is called to insert the literal for stroking the path. \end{enumerate} Why such a complicated process? Why not have |\pgfpathlineto| directly call |\pgfsys@lineto| and be done with it? There are two reasons: % \begin{enumerate} \item The \pdf\ specification requires that a path is not interrupted by any non-path-construction commands. Thus, the following code will result in a corrupted |.pdf|: % \begin{codeexample}[code only] \pgfsys@moveto{0}{0} \pgfsys@setlinewidth{1} \pgfsys@lineto{10}{0} \pgfsys@stroke \end{codeexample} % Such corrupt code is \emph{tolerated} by most viewers, but not always. It is much better to create only (reasonably) legal code. \item A soft path can still be changed, while a hard path is fixed. For example, one can still change the starting and end points of a soft path or do optimizations on it. Such transformations are not possible on hard paths. \end{enumerate} \subsection{Starting and Ending a Soft Path} No special action must be taken in order to start the creation of a soft path. Rather, each time a command like |\pgfsyssoftpath@lineto| is called, a special token is added to the (global) current soft path being constructed. However, you can access and change the current soft path. In this way, it is possible to store a soft path, to manipulate it, or to invoke it. \begin{command}{\pgfsyssoftpath@getcurrentpath\marg{macro name}} This command will store the current soft path in \meta{macro name}. \end{command} \begin{command}{\pgfsyssoftpath@setcurrentpath\marg{macro name}} This command will set the current soft path to be the path stored in \meta{macro name}. This macro should store a path that has previously been extracted using the |\pgfsyssoftpath@getcurrentpath| command and has possibly been modified subsequently. \end{command} \begin{command}{\pgfsyssoftpath@invokecurrentpath} This command will turn the current soft path in a ``hard'' path. To do so, it iterates over the soft path and calls an appropriate |\pgfsys@xxxx| command for each element of the path. Note that the current soft path is \emph{not changed} by this command. Thus, in order to start a new soft path after the old one has been invoked and is no longer needed, you need to set the current soft path to be empty. This may seem strange, but it is often useful to immediately use the last soft path again. \end{command} \begin{command}{\pgfsyssoftpath@flushcurrentpath} This command will invoke the current soft path and then set it to be empty. \end{command} \subsection{Soft Path Creation Commands} \begin{command}{\pgfsyssoftpath@moveto\marg{x}\marg{y}} This command appends a ``move-to'' segment to the current soft path. The coordinates \meta{x} and \meta{y} are given as normal \TeX\ dimensions. \example One way to draw a line: % \begin{codeexample}[code only] \pgfsyssoftpath@moveto{0pt}{0pt} \pgfsyssoftpath@lineto{10pt}{10pt} \pgfsyssoftpath@flushcurrentpath \pgfsys@stroke \end{codeexample} % \end{command} \begin{command}{\pgfsyssoftpath@lineto\marg{x}\marg{y}} Appends a ``line-to'' segment to the current soft path. \end{command} \begin{command}{\pgfsyssoftpath@curveto\marg{a}\marg{b}\marg{c}\marg{d}\marg{x}\marg{y}} Appends a ``curve-to'' segment to the current soft path with controls $(a,b)$ and $(c,d)$. \end{command} \begin{command}{\pgfsyssoftpath@rect\marg{lower left x}\marg{lower left y}\marg{width}\marg{height}} Appends a rectangle segment to the current soft path. \end{command} \begin{command}{\pgfsyssoftpath@closepath} Appends a ``close-path'' segment to the current soft path. \end{command} \subsection{The Soft Path Data Structure} A soft path is stored in a standardized way, which makes it possible to modify it before it becomes ``hard''. Basically, a soft path is a long sequence of triples. Each triple starts with a \emph{token} that identifies what is going on. This token is followed by two dimensions in braces. For example, the following is a soft path that means ``the path starts at $(0\mathrm{bp}, 0\mathrm{bp})$ and then continues in a straight line to $(10\mathrm{bp}, 0\mathrm{bp})$''. % \begin{codeexample}[code only] \pgfsyssoftpath@movetotoken{0bp}{0bp}\pgfsyssoftpath@linetotoken{10bp}{0bp} \end{codeexample} A curve-to is hard to express in this way since we need six numbers to express it, not two. For this reasons, a curve-to is expressed using three triples as follows: The command % \begin{codeexample}[code only] \pgfsyssoftpath@curveto{1bp}{2bp}{3bp}{4bp}{5bp}{6bp} \end{codeexample} % \noindent results in the following three triples: % \begin{codeexample}[code only] \pgfsyssoftpath@curvetosupportatoken{1bp}{2bp} \pgfsyssoftpath@curvetosupportbtoken{3bp}{4bp} \pgfsyssoftpath@curvetotoken{5bp}{6bp} \end{codeexample} These three triples must always ``remain together''. Thus, a lonely |supportbtoken| is forbidden. In details, the following tokens exist: % \begin{itemize} \item \declare{|\pgfsyssoftpath@movetotoken|} indicates a move-to operation. The two following numbers indicate the position to which the current point should be moved. \item \declare{|\pgfsyssoftpath@linetotoken|} indicates a line-to operation. \item \declare{|\pgfsyssoftpath@curvetosupportatoken|} indicates the first control point of a curve-to operation. The triple must be followed by a |\pgfsyssoftpath@curvetosupportbtoken|. \item \declare{|\pgfsyssoftpath@curvetosupportbtoken|} indicates the second control point of a curve-to operation. The triple must be followed by a |\pgfsyssoftpath@curvetotoken|. \item \declare{|\pgfsyssoftpath@curvetotoken|} indicates the target of a curve-to operation. \item \declare{|\pgfsyssoftpath@rectcornertoken|} indicates the corner of a rectangle on the soft path. The triple must be followed by a |\pgfsyssoftpath@rectsizetoken|. \item \declare{|\pgfsyssoftpath@rectsizetoken|} indicates the size of a rectangle on the soft path. \item \declare{|\pgfsyssoftpath@closepath|} indicates that the subpath begun with the last move-to operation should be closed. The parameter numbers are currently not important, but if set to anything different from |{0pt}{0pt}|, they should be set to the coordinate of the original move-to operation to which the path ``returns'' now. \end{itemize}
\section{The Classification of Finite Abelian Groups} We will prove (the generalization of) the following theorem later when we look at modules: \begin{theorem}\label{classify_fin_abe} Every finite abelian group is isomorphic to a product of cyclic groups. \end{theorem} In this section, we shall look at the uniqueness criterion of this statement. In fact, this representation is not unique in general, but we can get some sort of a uniqueness statement. \begin{lemma} If $m,n$ are coprime, then $C_m\times C_n\cong C_{mn}$. \end{lemma} \begin{proof} Let $g_m$ be the generator of $C_m$ and $g_n$ be that of $C_n$, then $(g_m,g_n)\in C_m\times C_n$ has order $\gcd(m,n)=mn$. \end{proof} \begin{corollary} Let $G$ be a finite abelian group, then $G\cong C_{n_1}\times C_{n_2}\times\cdots\times C_{n_k}$ such that any $n_i$ is a prime power \end{corollary} \begin{proof} Let $n$ be a positive integer, then $n=p_1^{e_1}\cdots p_r^{e_r}$ where $p_i$ are distinct primes, then $$C_n\cong C_{p_1^{e_1}}\times \cdots\times C_{p_r^{e_r}}$$ by the preceding lemma. Combining this with the theorem gives the result. \end{proof} In fact, what we will prove is the following refinement of Theorem \ref{classify_fin_abe}. \begin{theorem}\label{fin_abe_struct} Let $G$ be a finite abelian group, then $G\cong C_{d_1}\times C_{d_2}\times\cdots\times C_{d_t}$ such that $1<d_1|d_2|d_3|\cdots|d_{t-1}|d_t$. \end{theorem} \begin{remark} The integers $n_1,n_2,\ldots$ are up to a reordering, and $d_1,d_2,\ldots$ are uniquely determined by the group $G$. The proof (which we omit) works by counting the elements of $G$ with every possible order (it is enough to consider prime powers though). \end{remark} \begin{example} 1. Abelian groups of order $8$ can only be $C_8,C_2\times C_4,C_2\times C_2\times C_2$.\\ 2. Abelian groups of order $12$ can only be $C_2\times C_2\times C_3\cong C_2\times C_6,C_4\times C_3\cong C_{12}$ \end{example}
\chapter{Holographic Wilson loops} As discussed in chapter \ref{ch:WilsonLoops}, Wilson loops are important gauge invariant observables that can play the role of order parameters of the different phases of the gauge theory. % Being non-local, there are also natural suggestions for their holographic dual. Let us describe the basic idea that lead to find the holographic dual of Wilson loops, in the context of AdS/CFT correspondence. We then summarize the results obtained for the Pilch-Warner supergravity. \section{In the $AdS_5 \times S^5$ background} \subsection{Fundamental representation} In the fundamental representation, the (Maldacena-)Wilson loop \eqref{maldacenaWL} describes the phase of a trajectory of an external quark. A way to introduce the massive quark is to consider $\mathcal{N}=4$ SYM theory with all the fields in the adjoint representation of $U(N+1)$ instead. Then, we break spontaneously the gauge group $U(N+1) \rightarrow U(N) \times U(1)$. In this way, the off-diagonal states of the scalars that were in the adjoint of $U(N+1)$ become fundamental quarks and anti-quarks in $U(N)$, which are massive due to the Higgs mechanism. This is a useful picture because, in string theory, it is equivalent to separating one D-brane from the original stack of $N+1$ coincident D3-branes. This produces excited open strings that stretch along the stack and the individual brane, with the mass proportional to the separation distance. Since we consider probe quarks (non-dynamical), the brane must be infinitely far away from the stack. The stretched strings not only source the gauge fields, but by pulling the $N$ branes, they cause deformation on the branes that are described by the scalar fields in \eqref{maldacenaWL}. The details of the derivation can be found in the appendix of \cite{Drukker:1999zq}. Now, let us consider the dual gravitational picture. The stack gravitates and the near-horizon geometry is $AdS_5 \times S^5$. Then the position of the single D-brane lays on the conformal boundary of $AdS_5$, i.e. $z\rightarrow 0$, and sits at a point on $S^5$. The probe particle moves on the single D-brane. The Wilson loop operator is then dual to the partition function of fundamental strings in $AdS_5 \times S^5$ whose worldsheets end on the same curve $C$ that defines the Wilson loop at the boundary, \cite{Maldacena:1998im}: \begin{equation} W(C) = \int_{C=\partial \Sigma} DX e^{-S_\text{string}[X]}. \end{equation} \begin{figure}[t] \begin{center} \includegraphics[width=11cm]{Images/WLcircle.pdf} \end{center} \caption{\label{fig:WLcircle} Circular Wilson loop as the minimal worldsheet area $\Sigma$ drawn by string ending in the contour $C$ at the boundary of $AdS_5$. } \end{figure} In the 't Hooft limit, which corresponds to classical supergravity limit, minimizing the bosonic string action is sufficient for the leading order, which is essentially the minimal worldsheet area. % \begin{equation} % W(C) \sim e^{-\sqrt{\lambda} A}. % \end{equation} Nevertheless, the area is infinite in $AdS$, hence we must regularize it. For example, the minimal surface that is dual to the circular Wilson loop in the fundamental representation is parametrized as \begin{equation} z(r)=\sqrt{R^2-r^2}, \quad r\in[0, R], \quad \phi\in[0, 2\pi]. \end{equation} This result can be obtained either by minimizing the string Nambu-Goto action \cite{Drukker:1999zq}, % \begin{equation} % S_\text{NG} = \dfrac{\sqrt{\lambda}}{2\pi} \int d^2 \sigma e^{\Phi/2} \sqrt{\text{det}} % \end{equation} or by exploiting the conformal symmetry, i.e. mapping the special conformal transformation of the straight line solution \cite{Berenstein:1998ij}. The induced worldsheet metric, that is the pullback of the background metric $g$ \eqref{metricAdS} in polar coordinates for some $x^i$, is: \begin{equation} ds^2 = \dfrac{L^2}{z^2}\left((1+z'^2) dr^2 + r^2 d\phi^2 \right). \end{equation} Then the on-shell (Nambu-Goto) action gives: \begin{eqnarray} S &=& T_\text{F1} \int \sqrt{\text{det} P[g]}\\ &=& \dfrac{\sqrt{\lambda}}{2\pi} \int_0^{2\pi} d\phi \int_{0}^{\sqrt{R^2-\epsilon^2}} dr \dfrac{r}{z^2} \sqrt{1+z'^2}\\ &=& \sqrt{\lambda} \left(\dfrac{R}{\epsilon}-1 \right). \label{minimalAction} \end{eqnarray} The correct prescription to regularize the action is to set the boundary cut-off at $z=\epsilon$, then, we remove the perimeter divergence \cite{Drukker:1999zq}. This regularization scheme will be used for other cases of Wilson loop dual computations. The finite remnant in \eqref{minimalAction} matches with the leading order field theory result \eqref{W1holographic}, i.e. \begin{equation} W_1 = e^{\sqrt{\lambda}}, \quad (N\rightarrow \infty \quad \text{and} \quad \lambda \rightarrow \infty). \end{equation} In order to compute the subleading correction % $\sqrt{2/\pi}\:\lambda^{-3/4}$ in \eqref{W1holographic}, the fermionic contribution must be taken into account. The full string action to use would be the Green-Schwarz action. Although it is not fully known in curved background, its quadratic order is known \cite{Cvetic:1999zs}, which suffices for 1-loop corrections. Its quartic order was also derived in \cite{Wulff:2013kga}. Many efforts have been put into finding the subleading correction \cite{Kruczenski:2008zk, Kristjansen:2012nz, Bergamin:2015vxa, Forini:2015bgo, Faraggi:2016ekd, Forini:2017whz} but no full matching has been achieved. The ambiguity in the path integral measure hindered this computation. % A way to evade it was to use the ratio of Wilson loops, and then the matching was proved for the ratio when expanding for small angles \cite{Forini:2017whz}. \subsection{Higher rank representations} The lesson from the fundamental Wilson loop suggests that the string dual of rank-$k$ representations must be an object that carries $k$ units of the string charge. Intuitively, if we consider a Wilson loop wrapped $k$ times around the contour (the $k$-fundamental representation), we would expect the worldsheet to puff up, due to repulsive charges from multiple coincident fundamental strings. We see that the individual string action is no longer useful in this case. Instead, we can describe the new object in terms of D-branes with fundamental string charges dissolve in it. % The charges are the source of a worldvolume electric field in the DBI action (ref). The worldvolume must also pinch off at the boundary of $AdS_5$, ending along the curve defined by the Wilson loop, see figure \ref{fig:WLcircle}. Supersymmetry will then guide us which D-brane configurations are allowed. \begin{figure}[t] \begin{center} \includegraphics[width=11cm]{Images/DbraneWL.pdf} \end{center} \caption{\label{fig:DbraneWL} Circular Wilson loop of rank $k$ as a D-brane with $k$ string charges dissolved in it and the worldvolume ends in the contour $C$ at the boundary of $AdS_5$. } \end{figure} More generally, \cite{Gomis:2006sb} related supersymmetric Wilson loops of any representation of the gauge group to a stack of bulk D3-branes or a stack of bulk D5-branes, see figure \ref{fig:YoungTable}. They proved the correspondence by explicitly integrating out the physics on the D-branes, which results to a half-BPS Wilson loop insertion in the desired representation in the $\mathcal{N}=4$ SYM path integral. \begin{figure}[t] \begin{center} \includegraphics[width=7cm]{Images/YoungTable.png} \end{center} \caption{\label{fig:YoungTable} A generic Young table, taken from \cite{Gomis:2006sb}. Row $i$ corresponds to a D3-brane with $n_i$ fundamental string charge dissolved in it. Column $j$ corresponds to a D5-brane with $m_j$ fundamental string charge dissolved in it. Thus, for symmetric (one row) and antisymmetric (one column) representations, their rank $k$ corresponds to the string charges a D3-brane and a D5-brane contains.} \end{figure} Let us focus on a single D3-brane and a single D5-brane. Consider first the line element for $AdS_5\times S^5$ is this convenient form: \begin{equation} ds^2 = L^2 \left( du^2 + \cosh^2 u \,d\check{\Omega}^2 + \sinh^2 u \, d\Omega_2^2 + d\theta^2 + \sin^2 \theta \, d\Omega_4^2 \right), \end{equation} where $u\geq 0$, and $\pi \geq \theta \geq 0 $. $d\check{\Omega}_n^2$ and $d\Omega_n^2$ indicate the line element for $AdS_n$ and $S^n$, respectively. % and we use global coordinates to parametrize $AdS_2$ line element: % \begin{equation} % d\check{\Omega}^2 =d\chi^2+\sinh^2\chi d\varphi^2, \quad \chi\geq 0, \quad 2 \pi \geq \varphi \geq 0. % \end{equation} Using the supersymmetry condition\footnote{ May be up to a sign depending on the conventions.} \begin{equation}\label{susyCondition} \Gamma \epsilon = \epsilon, \end{equation} where $\Gamma$ is the kappa symmetry\footnote{ It is a fermionic local gauge symmetry that is present also in particles and strings. Its full definition can be found in Paper III.} projector for the D-brane and $\epsilon$ is the Killing spinor of the background geometry, we can find the D-brane embeddings that preserve half of the original supersymmetries. Note that the supersymmetry condition, which gives first order differential equations, imply the D-brane equations of motions, which are of second order, up to some integration constants. The list below shows the half-BPS D-brane embeddings with their worldvolume geometries induced from the target space, and the worldvolume gauge fields $F$ \cite{Yamaguchi:2006tq}: \begin{eqnarray} \text{D3-brane:} &\quad& AdS_2 \times S^2, \quad u=\text{constant}, \quad \theta = 0 \\ &\quad& \dfrac{1}{T_{F1}}F = L^2\sqrt{1+\kappa^2} e^0 e^1, \quad \kappa \equiv \sinh u \\ \text{D5-brane:} &\quad& AdS_2 \times S^4, \quad u=0, \quad \theta = \text{constant} \\ &\quad& \dfrac{1}{T_{F1}}F = L^2 \cos \theta e^0 e^1 \end{eqnarray} where $e^0$ and $e^1$ are the vielbeins\footnote{ Vielbeins are defined by $ds^2=\eta_{mn} e^m e^n$, which is often referred as the \emph{local frame}. In terms of components: $e^m=e^m_M dx^M$, thus, we can relate them to the metric as $g_{MN} = \eta_{mn} e^m_M e^n_M$.} of $d\check{\Omega}^2$. We see that the D3-brane sits on a fixed point on the $S^5$, while the D5-brane sits on $S^4$ that is $\theta$ angle away from the pole of $S^5$, see figure \ref{fig:S5}. \begin{figure}[t] \begin{center} \includegraphics[width=4cm]{Images/S5.png} \end{center} \caption{\label{fig:S5} $S^4$ that is $\theta$ angle away from the pole of $S^5$. The angle depends on the amount of string charges $k$ that D5-brane contains.} \end{figure} The dual counterparts of the symmetric/antisymmetric representation in the leading order 't Hooft limit are the on-shell action DBI \eqref{DBI} + WZ \eqref{WZ} of the D3-brane/D5-brane configuration aforementioned: \begin{equation}\label{WLDbrane} \log W^{+}_k = - S_{D3}, \quad \log W^{-}_k = - S_{D5}. \end{equation} Moreover, we must ensure the string charge $k$ constraint, which can be added as a Lagrange multiplier term to the D-brane action: \begin{equation} \label{stringChargeConstraint} S_k = - k \int_\Sigma F \quad \Rightarrow \quad k = \dfrac{1}{T_{F1}} \dfrac{\delta S_\text{DBI}}{\delta F} . \end{equation} The couplings in terms of $\lambda$ and $N$ are: \begin{equation} T_\text{F1} = \dfrac{\sqrt{\lambda}}{2\pi L^2}, \quad % T_\text{D1} = \dfrac{2N}{\sqrt{\lambda}}, % \quad T_\text{D3} = \dfrac{N}{2\pi^2 L^4}, \quad T_\text{D5} = \dfrac{N\sqrt{\lambda}}{8\pi^4 L^6}, \end{equation} which are derived from \eqref{couplingsTension} using \eqref{couplings}. Finally, the regularized actions are \cite{Drukker:2005kx, Yamaguchi:2006tq, Zarembo:2016bbk}: \begin{eqnarray} S_\text{D3} &=& - 2 N (\kappa\sqrt{1+\kappa^2}+\mathop{\mathrm{arcsinh}}\kappa)\\ S_\text{D5} &=& - N \frac{2\sqrt{\lambda }}{3\pi}\,\sin^3\theta, \end{eqnarray} with the $\theta$ satisfying the string charge constraint \eqref{stringChargeConstraint} that gives \eqref{eqThetaAntisym}, i.e. \begin{equation} \theta -\frac{1}{2}\,\sin 2\theta =\pi \frac{k}{N}. \end{equation} Thus the latitude angle $\theta$ depends on the amount of string charges $k$ dissolved in the D5-brane. In conclusion, there is an exact agreement with \eqref{solW+} and \eqref{solW-}, according to \eqref{WLDbrane}. \section{In Pilch-Warner background} In $\mathcal{N}=2^*$ SYM on $S^4$, we took the decompactification limit for circular Wilson loops in order to have results on $\mathbb{R}^4$. This means that in the Pilch-Warner background, the contour is a straight line of length $l\rightarrow \infty$. \subsection{Fundamental representation} The minimal surface of a straight Wilson line is a wall, with the worldsheet coordinates $(\tau, \sigma)$ induced from the Pilch-Warner geometry in the following way: \begin{equation} \tau = x^1, \quad \sigma = c. \end{equation} The regularized on-shell action was computed in \cite{Buchel:2013id}, which agrees with the leading order result in \eqref{WLFundN2}, that is: \begin{equation}\label{W1leading} \log W_1 = \sqrt{\lambda} M \frac{l}{2\pi }, \quad (l\rightarrow \infty). \end{equation} The goal of Paper V was to compute the loop corrections to the minimal surface by using string perturbation around the above classical solution. There are two contributions, which turned out to be of equal weight in our case. The first one comes from the dilaton coupling to the worldsheet curvature called the Fradkin-Tseytlin term \cite{Fradkin:1983xs}: \begin{equation} S_{FT}=\dfrac{1}{4\pi} \int d^2\sigma \sqrt{h} R^{(2)} \Phi, \end{equation} which is actually a bit controversial, with some authors arguing it is not needed \cite{GRISARU1988625, GRISARU1985116, Cvetic:1999zs}. Besides, it is zero for the familiar $AdS_5 \times S^5$ background due to a vanishing dilaton. % explicitly break the conformal invariance of the classical world-sheet action The other one comes from 1-loop stringy corrections, which are computed by expanding the Green-Schwarz action up to quadratic fluctuations \cite{Cvetic:1999zs}. These contribute as functional determinants, from generalizing the Gaussian integration formula \eqref{GaussianIntegral} for the bosons, and the Grassmann integration for the fermions \eqref{GrassmannIntegral}. Thus the semiclassical partition function is schematically of the form \begin{equation} W = e^{-S_\text{cl}-S_\text{FT}} \dfrac{\text{det} F}{\sqrt{\text{det} B}}, \end{equation} where $S_\text{cl}$ is the classical on-shell action in \eqref{W1leading}, $B$ and $F$ here just represent the bosonic and fermionic operators. % of Schroedinger type (second order differential operator), % of Dirac type ($2\times2$ first order differential operator). Supersymmetry simplifies our problem by cancelling exactly the sector of bosonic and fermionic operators that are asymptotically massless (far away from the boundary $\sigma=1$). The remaining sector is asymptotically massive, and the operators (after several manipulations) look enticingly similar: \begin{equation}\label{basicDirac} H_B=\begin{pmatrix} 1+\frac{A}{\sigma } & \mathcal{L} \\ \mathcal{L}^\dagger & -1 \\ \end{pmatrix},\qquad H_F=\begin{pmatrix} -1 & \mathcal{L} \\ \mathcal{L}^\dagger & 1+\frac{A}{\sigma } \\ \end{pmatrix}, \end{equation} with \begin{eqnarray}\label{EuclideanLs} \mathcal{L}&=&A\sqrt{\sigma ^2-1}\,\partial _\sigma +\frac{A\left(2\sigma ^2+1\right)}{2\sigma \sqrt{\sigma ^2-1}} , \nonumber \\ \mathcal{L}^\dagger &=&-A\sqrt{\sigma ^2-1}\,\partial _\sigma -\frac{A\left(4\sigma ^2-1\right)}{2\sigma \sqrt{\sigma ^2-1}} +\frac{2}{\sqrt{\sigma ^2-1}}\,. \end{eqnarray} The final semiclassical partition function to compute is then: \begin{equation}\label{semiclassicalW} W = e^{-S_\text{cl}-S_\text{FT}}\dfrac{\text{det}^2 (\partial_\tau-H_F)}{\text{det}^2 (\partial_\tau-H_B)}, \end{equation} Instead of using the heat kernel technique or the Gelfand-Yaglom method, both commonly used in the computation of functional determinants, we used the phase-shift method from quantum mechanical scattering problems, see e.g. \cite{PhysRevD.10.4130}. The method requires the operators to be asymptotically free, hence it works for (semi-)infinite intervals. Our operators \eqref{basicDirac} share the same asymptotics in large $\sigma$, and they are defined in a semi-infinite interval $\sigma>1$, so the method applies. Note that for $\tau$ variable, we do a usual Fourier transformation. The exponential of the ratio of the determinants of the operators in \eqref{semiclassicalW} can be written in terms of the phase-shift $\delta(p)$ between the wave function and the asymptotic plane wave, see figure \ref{fig:potentialWavesPlot}, which is \begin{equation}\label{deltaphases} -2 \, \int_{0}^{\infty }\frac{dp}{2\pi }\,\, \frac{4 p }{9\sqrt{\frac{4}{9}\,p^2+1}}\,\left( \delta_F ^+(p) + \delta_F ^-(p) -\delta_B ^+(p) - \delta_B^-(p) \right) = -\dfrac{1}{4}, \end{equation} where $\pm$ distinguish the two eigenvectors (particles and holes) of the Dirac Hamiltonians \eqref{basicDirac}. The last equality is backed by our numerics. Thus, together with the Fradkin-Tseytlin contribution, the total correction is $-1/2$. In conclusion, we do have a perfect matching with the field theory result \eqref{WLFundN2}. % up to the subleading order in strong coupling expansion. Moreover, the existence of Fradkin-Tseytlin term is necessary for this agreement. \begin{figure}[t] \begin{center} \includegraphics[width=0.7\textwidth]{Images/potentialWavesPlotBlack.pdf} \end{center} \caption{\label{fig:potentialWavesPlot} Phase-shift $\delta(p)$ of the wave function in the presence of a typical potential wall that many of our operators show, versus the free wave, for certain momentum $p$. } \end{figure} \subsection{Symmetric representation} As for higher rank Wilson loops, Paper III found the D3-brane embedding dual to the straight Wilson line of length $l$ in symmetric representation, with the help of the supersymmetric condition \eqref{susyCondition}. The worldvolume metric is induced from the deformed $AdS$ part of \eqref{metricPW} in string frame\footnote{ We changed to mostly minus signature in order to follow Paper III. The string metric $g$ and the Einstein metric $G$ are related by $g=e^{-\frac{4 \Phi }{D-2}} G$, where $\Phi$ is the dilaton. }: \begin{equation} ds^2 = \dfrac{A M^2 L^2}{c^2-1}\left(dx^2 - \rho(c)^2 d\Omega_2^2 \right) -L^2\left(\dfrac{1}{A \left(c^2-1\right)^2} + \dfrac{A M^2 \rho'(c)^2}{c^2-1} \right) dc^2, \end{equation} where \begin{equation} \rho(c)= \kappa \, \sqrt{c^2-1}, \end{equation} since the deformed sphere shrinks to $\theta=\pi/2$ and $\phi=0$. The worldvolume gauge field is given by \begin{equation} \frac{1} {T_\text{F1}} F (c) = -\dfrac{M L^2}{(c^2-1)^{3/2}} dx\wedge dc. \end{equation} As expected, it also reduces to the analogous case in $AdS_5 \times S^5$ close to the boundary. The regularized on-shell action reduces to \begin{equation} S_{D3} = - \sqrt{\lambda} k M \dfrac{l}{2\pi}. % , \quad (l \rightarrow \infty). \end{equation} This agrees with the matrix model result \eqref{WsymPW} according to \eqref{WLDbrane}, only in the low rank limit \begin{equation} \kappa \ll M l. \end{equation} Furthermore, for $k=1$, we recover the fundamental case \eqref{W1leading}. We can conclude that this D3-brane configuration cannot probe the entire matrix model region, and a full dual object is still to be understood. For the antisymmetric case, it is technically challenging to find the D5-brane solution. So far, we have not succeeded. We do expect it though to match the leading order field theory result, because the matrix model result \eqref{WantisymPW} is proportional to $Ml$, the same as in the D-brane action. It would be definitely interesting to compute the subleading order to determine the phase-transitions observed.
\documentclass{scrreprt} \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage{lmodern} \begin{document} \setkomafont{section}{\LARGE} \thispagestyle{empty} \section*{Friday -- Hamersley South (Small Panel Room)}\begin{description} \Large \item[10:00 -- 11:00]{A Guide to Femslash Fandom} \item[11:00 -- 13:00]{Natcon Business Meeting} \item[14:00 -- 15:00]{Then and Now: A comparison between 2015 and 1974 in the SFF scene.} \item[16:00 -- 17:00]{2014 Movie Screenings: A Recap} \item[17:00 -- 18:00]{Introduction to Worldcon} \item[19:30 -- 20:30]{Unusual Pairings in FanFic - the Good, the Bad, the Ugly} \item[20:30 -- 21:30]{Beyond IO9: Online sources of our fannish hits} \item[21:30 -- 22:30]{(Over-used) Fan-Fiction Tropes} \item[22:30 -- 23:30]{YouTube-a-Rama: The strangest fannish stuff we love from YouTube.}\end{description} \newpage \thispagestyle{empty} \section*{Friday -- Centre Ballroom (Med Ballroom)}\begin{description} \Large \item[10:00 -- 11:00]{Lucy M Boston – An Appreciation} \item[14:00 -- 14:15]{FF - Poison Elves Comic} \item[14:15 -- 14:30]{FF - Ancillary Justine by Annie Leckie} \item[14:30 -- 14:45]{FF - Collected works of Neil Gaiman and Amanda Palmer in 10 minutes} \item[14:45 -- 15:00]{FF - True Detective} \item[15:00 -- 16:00]{The History of Studio Ghibli - Conclusion} \item[16:00 -- 17:00]{From Asimov to Zelazny: upholding the classics} \item[17:00 -- 18:00]{Big Dumb Objects: The Giant Artefacts of Science Fiction} \item[19:30 -- 20:30]{Is the Best of Comics Found in Non-Canon Works?} \item[21:30 -- 22:30]{Jonathan's God Panel}\end{description} \newpage \thispagestyle{empty} \section*{Friday -- Gaming Room (Goldsworthy)}\begin{description} \Large \item[09:00 -- 10:00]{Learn Splendor} \item[10:00 -- 12:00]{The Hollow Reaches Playtest (2)} \item[14:00 -- 16:00]{Tournament - Dixit} \item[16:00 -- 17:00]{Learn Take 6!} \item[17:00 -- 18:00]{Learn Ticket to Ride: Europe} \item[18:00 -- 19:00]{Learn Survive! Escape from Atlantis!} \item[19:00 -- 20:00]{WABA Love Letter Tournament} \item[20:00 -- 21:00]{Learn Splendor} \item[21:00 -- 22:00]{Learn Ogre}\end{description} \newpage \thispagestyle{empty} \section*{Friday -- Alternate Venue (Check Details)}\begin{description} \Large \item[11:00 -- 12:00]{Kaffeeklatch - Kylie Chan (1)} \item[12:00 -- 13:00]{Kaffeeklatsch - Helen Stubbs} \item[14:00 -- 15:00]{Kaffeeklatsch - John Scalzi} \item[15:00 -- 16:00]{Kaffeeklatsch - Glenda Larke} \item[16:00 -- 17:00]{Kaffee Klatsch - Kylie Chan (2)} \item[17:00 -- 18:00]{Kaffeeklatch - Donna Maree Hansen}\end{description} \newpage \thispagestyle{empty} \section*{Friday -- North Ballroom (Large ballroom)}\begin{description} \Large \item[10:00 -- 11:00]{Blood, Bodices and Vincent Price: Looking ar the Horror works of Roger Corman} \item[11:00 -- 12:00]{Ladies Comic Book Club} \item[12:00 -- 13:00]{GOH - Speech - Anthony Peacey} \item[14:00 -- 15:00]{Loving The Borg: Transhumanism in the Real World.} \item[16:00 -- 17:00]{Changing Communities with Intent} \item[17:00 -- 18:00]{Trailer Park - Asian Cinema} \item[19:30 -- 20:00]{Awards Setup and Prep} \item[20:00 -- 23:30]{Awards - Ditmars, Tin Ducks, ETC}\end{description} \newpage \thispagestyle{empty} \section*{Friday -- North Hamersley (Gaming and Others)}\begin{description} \Large \item[10:00 -- 11:00]{Old Games are New Again: The revival of classics in new ways} \item[11:00 -- 12:00]{Reading Lite Gaming} \item[12:00 -- 13:00]{Social Media, Marketing and Writing} \item[14:00 -- 15:00]{Retro Games with Andy} \item[15:00 -- 16:00]{Spec Fic Writing - Science Potrayal in Fiction} \item[16:00 -- 17:00]{Doctor Who in Australia: The Blue Box, Downunder} \item[17:00 -- 18:00]{Short and Sweet: Games you can play in under 30 minutes} \item[19:30 -- 20:30]{This game is so good, I'm prepared to speak for 3 minutes in public on it. (1)}\end{description} \newpage \thispagestyle{empty} \section*{Friday -- Pilbara (Video Game Stream)}\begin{description} \Large \item[09:00 -- 10:00]{Open Console Gaming} \item[10:00 -- 13:00]{Retro Gaming!} \item[14:00 -- 15:30]{Portal 2 Co-op} \item[15:30 -- 18:00]{Spyro Co-op!} \item[19:30 -- 23:00]{Griff Ball}\end{description} \newpage \thispagestyle{empty} \section*{Friday -- Family Room (Boardroom)}\begin{description} \Large \item[09:30 -- 11:00]{General Crafting} \item[11:00 -- 11:30]{Circuits: A How-To Guide - mini panel} \item[11:30 -- 12:00]{Egg-Bot and Easter Egg Decorating} \item[12:00 -- 13:00]{Easter Egg Hunt} \item[14:00 -- 14:30]{Quiet Reading} \item[14:30 -- 15:00]{Build Your Own SPACESHIP!} \item[15:00 -- 15:30]{Reading 3} \item[15:30 -- 16:00]{Guardian Princess Alliance - mini panel} \item[16:00 -- 16:30]{Make Your Own Game} \item[16:30 -- 17:00]{Free Time - Play Your Games} \item[17:00 -- 18:00]{Plush Toy Wars}\end{description} \newpage \thispagestyle{empty} \section*{Friday -- South Ballroom (Traders and Art Show Room)}\begin{description} \Large \item[09:00 -- 12:00]{Swap Meet (And Artshow)} \item[12:00 -- 13:00]{Swapmeet Breakdown} \item[14:00 -- 16:00]{Rebel Empire Workshops Performance} \item[16:00 -- 16:30]{Fundraising Auction - Setup} \item[16:30 -- 18:30]{Fundraising Auction (And Art Show)}\end{description} \newpage \thispagestyle{empty} \section*{Saturday -- Hamersley South (Small Panel Room)}\begin{description} \Large \item[11:00 -- 13:00]{WASFF Business Meeting} \item[14:00 -- 14:30]{Trailer Park - Children and Families} \item[15:00 -- 16:00]{"Not Dead Yet" - 40 years of Monty Python and the Holy Grail}\end{description} \newpage \thispagestyle{empty} \section*{Saturday -- Centre Ballroom (Med Ballroom)}\begin{description} \Large \item[10:00 -- 11:00]{State of the Art Director: What can (and cannot) be done in SFX} \item[11:00 -- 12:00]{Anthony and Grant The Non-Writerly Interview} \item[12:00 -- 13:00]{What do we wear from here?: The future of Smart Wearables} \item[14:00 -- 15:00]{Homework Panel for 2016} \item[15:00 -- 16:00]{SMOF, Dane and Filk: Exploring the geek lexicon} \item[16:00 -- 16:30]{Closing Ceremony}\end{description} \newpage \thispagestyle{empty} \section*{Saturday -- Gaming Room (Goldsworthy)}\begin{description} \Large \item[09:00 -- 10:00]{Learn Splendor} \item[11:00 -- 12:00]{Learn Take 6!} \item[13:00 -- 14:00]{Learn Ticket to Ride: Europe}\end{description} \newpage \thispagestyle{empty} \section*{Saturday -- North Ballroom (Large ballroom)}\begin{description} \Large \item[10:00 -- 11:00]{Forgotten TV Animation: the Hidden Gems} \item[11:00 -- 12:00]{History of Roguelikes - from Rogue to Crawl} \item[12:00 -- 13:00]{Podcasting Your Passion} \item[14:00 -- 15:00]{Please Hammer, Don't Hurt 'em: The lesser known Hammer Horror movies.} \item[15:00 -- 16:00]{Dark Dungeons: Who is Jack Chick?}\end{description} \newpage \thispagestyle{empty} \section*{Saturday -- Pilbara (Video Game Stream)}\begin{description} \Large \item[09:00 -- 13:00]{Open Console Gaming} \item[13:00 -- 16:00]{Pack Up}\end{description} \newpage \thispagestyle{empty} \section*{Saturday -- North Hamersley (Gaming and Others)}\begin{description} \Large \item[10:00 -- 11:00]{The Science of Board Game Design} \item[11:00 -- 12:00]{This game is so good, I'm prepared to speak for 3 minutes in public on it. (2)} \item[12:00 -- 13:00]{Everyone take a Chill Pill!: Non-violent RPGs and computer games.} \item[14:00 -- 15:00]{Apocalypse During Swancon - Group Workshop} \item[15:00 -- 16:00]{Australian Game Design and History}\end{description} \newpage \thispagestyle{empty} \section*{Saturday -- Family Room (Boardroom)}\begin{description} \Large \item[09:30 -- 11:00]{General Crafting} \item[11:00 -- 11:30]{How To Stump A Scientist - mini panel} \item[11:30 -- 12:00]{KitKat Jenga} \item[12:00 -- 13:00]{Live Action Quiddich} \item[14:00 -- 14:30]{Quiet Reading} \item[14:30 -- 15:00]{How To Origami} \item[15:00 -- 15:30]{Reading 4} \item[15:30 -- 16:00]{Minecraft - Mini Panel} \item[16:00 -- 16:30]{Design Your Own Superhero} \item[16:30 -- 18:00]{Pack Up}\end{description} \newpage \thispagestyle{empty} \section*{Saturday -- South Ballroom (Traders and Art Show Room)}\begin{description} \Large \item[10:00 -- 13:00]{Live Action Robo Rally} \item[14:00 -- 15:00]{Nerf Games 2015} \item[15:00 -- 16:00]{Swancon Feedback Panel}\end{description} \newpage \thispagestyle{empty} \section*{Tuesday -- Hamersley South (Small Panel Room)}\begin{description} \Large \item[19:00 -- 19:30]{Meet the Swancon A/V guy} \item[19:30 -- 20:00]{Moderate Moderators: The HOWTO panel} \item[20:00 -- 21:00]{Voyager: a Celebration} \item[21:00 -- 22:00]{Land of the Setting Sun: The End of Anime?} \item[22:00 -- 23:00]{The Reverse of the Return of the Sequel to the Trilogy of Just Who's Line?}\end{description} \newpage \thispagestyle{empty} \section*{Tuesday -- Centre Ballroom (Med Ballroom)}\begin{description} \Large \item[19:00 -- 20:00]{Hanna-Barbera Part 2} \item[20:00 -- 21:00]{9th Year of the Video Quiz: Swancon Birthday Edition} \item[21:00 -- 22:00]{Riding The Iron Bull: Why Is Dragon Age Inquisition So Damn Good?}\end{description} \newpage \thispagestyle{empty} \section*{Tuesday -- Gaming Room (Goldsworthy)}\begin{description} \Large \item[16:00 -- 17:00]{MeepleAngel (gaming room helpers) Orientation} \item[20:00 -- 21:00]{Learn Ugg-Tect} \item[21:00 -- 22:00]{Learn Take 6!}\end{description} \newpage \thispagestyle{empty} \section*{Tuesday -- North Ballroom (Large ballroom)}\begin{description} \Large \item[19:00 -- 20:00]{Depiction of Religion in Science Fiction and Fantasy} \item[20:00 -- 21:00]{The Warrior Awakens: Military Sci Fi - an Appreciation} \item[21:00 -- 22:00]{Trailer Park - Adult Themes}\end{description} \newpage \thispagestyle{empty} \section*{Tuesday -- Pilbara (Video Game Stream)}\begin{description} \Large \item[16:00 -- 18:30]{Setup - Video Game Room} \item[19:00 -- 22:00]{Open Console Gaming}\end{description} \newpage \thispagestyle{empty} \section*{Tuesday -- North Hamersley (Gaming and Others)}\begin{description} \Large \item[20:00 -- 21:00]{Genderbending in Fanworks: Does my genderflip invalidate your slash and other questions?} \item[21:00 -- 22:30]{Under Construction - Convention Theme}\end{description} \newpage \thispagestyle{empty} \section*{Tuesday -- Family Room (Boardroom)}\begin{description} \Large \item[12:30 -- 14:30]{Set-Up} \item[14:30 -- 18:30]{Sign-In and Registration}\end{description} \newpage \thispagestyle{empty} \section*{Wednesday -- Hamersley South (Small Panel Room)}\begin{description} \Large \item[10:00 -- 11:00]{Reframed and Repackaged: SF as literature} \item[12:00 -- 13:00]{The Big Finish: Full cast radio plays make a comeback.} \item[14:00 -- 15:00]{Terrors of the Second Draft} \item[15:00 -- 16:00]{Anime (and Manga) for ABSOLUTE Beginners} \item[16:00 -- 17:00]{The Writer's Interview: John Scalzi and Grant Watson} \item[17:00 -- 18:00]{Before the Flood: Anime in Australia before the 90s} \item[19:30 -- 20:30]{Swancon History Panel 0 - 20 Years} \item[20:30 -- 21:30]{Intersections Between Sex and Technology} \item[21:30 -- 23:59]{Beefcake!!! The Third}\end{description} \newpage \thispagestyle{empty} \section*{Wednesday -- Centre Ballroom (Med Ballroom)}\begin{description} \Large \item[10:00 -- 11:00]{Ant Who Now? Characters who deserve a movie before Antman} \item[12:00 -- 13:00]{Christopher vs Collins: Dystopias Past and Present} \item[14:00 -- 15:00]{Costuming for Fun and Effect!} \item[15:00 -- 16:00]{The Writer's Interview: Kylie Chan} \item[16:00 -- 17:00]{The End of the Printed Page: Are Books (as we know them) Dead?} \item[17:00 -- 18:00]{Who Owns "Culture", anyway? Working outside your own.} \item[19:30 -- 20:30]{Ch.ch.ch.changes: SF\&F as a transformative force upon Society} \item[20:30 -- 21:30]{Beauty \& the Beast: The Original Werewolf Tale?} \item[21:30 -- 22:30]{The Batman Problem: The Dark Nut Returns} \item[22:30 -- 23:30]{Evil Overlord Training School}\end{description} \newpage \thispagestyle{empty} \section*{Wednesday -- Gaming Room (Goldsworthy)}\begin{description} \Large \item[09:00 -- 10:00]{Learn Splendor} \item[10:00 -- 11:00]{Halfling Heist} \item[12:00 -- 13:00]{Learn Ogre} \item[14:00 -- 15:00]{Learn Take 6!} \item[15:00 -- 16:00]{Learn Ugg-Tect} \item[16:00 -- 17:00]{Learn Ticket to Ride: Europe} \item[17:00 -- 18:00]{Halfling Heist} \item[19:00 -- 20:00]{Learn Ticket to Ride: Europe} \item[20:00 -- 21:00]{Learn Splendor}\end{description} \newpage \thispagestyle{empty} \section*{Wednesday -- North Ballroom (Large ballroom)}\begin{description} \Large \item[09:45 -- 10:00]{Welcome to Swancon} \item[10:00 -- 11:00]{Gods and Monsters: Doctor Who's 13th Season} \item[11:00 -- 12:00]{GoH - Speech - Kylie Chan} \item[12:00 -- 13:00]{GoH Kylie Chan Signing} \item[13:45 -- 14:00]{Welcome to Swancon} \item[14:00 -- 15:00]{Teenage Juggernaut: The Runaway Success of Young Adult Fiction} \item[15:00 -- 16:00]{Sci Fi and Horror TV Anthologies} \item[16:00 -- 17:00]{Enligtenment vs Resistance: Ingress, a globetrotting real world MMO.} \item[17:00 -- 19:30]{40th Birthday Party} \item[19:30 -- 21:30]{Let's build a Civilisation: One Continent} \item[21:30 -- 22:30]{Scared S\#!\%less: How Horror Movies Work}\end{description} \newpage \thispagestyle{empty} \section*{Wednesday -- Pilbara (Video Game Stream)}\begin{description} \Large \item[09:00 -- 10:00]{Open Console Gaming} \item[10:00 -- 13:00]{Hyrule Warriors} \item[14:00 -- 15:30]{Mario Kart WiiU} \item[15:30 -- 18:00]{Super Smash Bros WiiU/3DS} \item[19:30 -- 23:00]{Halo 4}\end{description} \newpage \thispagestyle{empty} \section*{Wednesday -- North Hamersley (Gaming and Others)}\begin{description} \Large \item[09:30 -- 10:30]{Drawing Composite monsters: A collaboration} \item[10:30 -- 10:45]{FF - Bees} \item[10:45 -- 11:00]{FF - How To Be More Skeptical 101} \item[12:00 -- 13:00]{Food as Worldbuilding} \item[14:00 -- 15:00]{How to be a good GM (Pt 1 of 2)} \item[15:00 -- 16:00]{More than just extra Umlats: Names and naming conventions in SF/F} \item[16:00 -- 17:00]{How to be a good RPGer (Pt 2 of 2)} \item[17:00 -- 18:00]{Writing Video Games for Fun and Profit} \item[19:30 -- 19:45]{FF - Agent Carter} \item[19:45 -- 20:00]{FF - Defiance} \item[20:00 -- 20:15]{FF - Black Mirror} \item[20:15 -- 20:30]{FF - Why Once Upon A Time is Better than Fanfiction} \item[20:30 -- 22:00]{Under Construction - Finding and Keeping Committee} \item[22:00 -- 00:00]{GWEN Live stream (Up From Down Under with Michael)}\end{description} \newpage \thispagestyle{empty} \section*{Wednesday -- Family Room (Boardroom)}\begin{description} \Large \item[09:30 -- 11:00]{Creche Rhymes} \item[11:00 -- 11:30]{Horrible Histories - mini panel} \item[11:30 -- 12:00]{Pocky Ker-Plunk} \item[12:00 -- 13:00]{Juggling: A How-To Guide} \item[14:00 -- 14:30]{Quiet Reading} \item[14:30 -- 15:00]{The Basics of Drawing} \item[15:00 -- 15:30]{Reading 1} \item[15:30 -- 16:30]{Make-Your-Own Instruments} \item[16:30 -- 18:00]{Geekling Sing-A-Long}\end{description} \newpage \thispagestyle{empty} \section*{Wednesday -- South Ballroom (Traders and Art Show Room)}\begin{description} \Large \item[10:00 -- 18:00]{Traders and Art Show}\end{description} \newpage \thispagestyle{empty} \section*{Thursday -- Hamersley South (Small Panel Room)}\begin{description} \Large \item[10:00 -- 10:30]{Launch - Deborah Kalin - Cherry Crow Children} \item[10:30 -- 11:00]{Launch - Tehani Wessely - "Insert Title Here"} \item[12:00 -- 12:30]{Dave Luckett - Reading - 'Legacy of Scars'} \item[12:30 -- 13:00]{Robert Hood - Reading - 'Peripheral Visions'} \item[13:45 -- 14:00]{Welcome to Swancon} \item[14:00 -- 15:00]{Climate Change - is it Affecting our Spec Fic?} \item[15:00 -- 16:00]{What's happening with the Square Kilometre Array, and the Murchison Widefield Array} \item[16:00 -- 17:00]{Looking Beyond the Left Hand: Gender and Sexuality in Contemporary SF} \item[17:00 -- 18:00]{New Who: The Capaldi Continuum}\end{description} \newpage \thispagestyle{empty} \section*{Thursday -- Centre Ballroom (Med Ballroom)}\begin{description} \Large \item[10:00 -- 11:00]{Trailer Park - Mainstream Movies} \item[12:00 -- 13:00]{Return of the Editors Strike Back} \item[14:00 -- 14:15]{FF - Orphan Black} \item[14:15 -- 14:30]{FF - Hanako Games} \item[15:00 -- 16:00]{SciFi Yet Skeptical} \item[16:00 -- 17:00]{The Sword Drawn! Kitty and John Explore Excalibur} \item[17:00 -- 18:00]{Magical and SF Detective Fiction: Police Procedurals and similar in non mainstream settings.} \item[21:30 -- 22:30]{Paranormal Romance : What hasn't been done?} \item[22:30 -- 23:30]{Sing-Along with Sauron}\end{description} \newpage \thispagestyle{empty} \section*{Thursday -- Gaming Room (Goldsworthy)}\begin{description} \Large \item[10:00 -- 11:30]{Tournament - Halfling Heist} \item[11:30 -- 13:00]{The Hollow Reaches Playtest (1)} \item[14:00 -- 15:00]{Learn Ticket to Ride: Europe} \item[15:00 -- 16:00]{Learn Splendor} \item[16:00 -- 17:00]{Learn Ugg-Tect} \item[17:00 -- 18:00]{Learn Survive! Escape from Atlantis!} \item[18:00 -- 19:00]{Learn Take 6!} \item[19:00 -- 20:00]{Learn Splendor}\end{description} \newpage \thispagestyle{empty} \section*{Thursday -- North Ballroom (Large ballroom)}\begin{description} \Large \item[09:45 -- 10:00]{Welcome to Swancon} \item[10:00 -- 11:00]{Just Imagine: Costumes in Early SF Films} \item[11:00 -- 12:00]{GoH - Speech - John Scalzi} \item[12:00 -- 13:00]{John Scalzi - Signing} \item[14:00 -- 14:30]{Launch 2016 Prep} \item[14:30 -- 15:00]{Launch 2016} \item[15:00 -- 16:00]{King Lizard: 60 years of Godzilla} \item[16:00 -- 18:00]{House of Cards: Disney Animation from 1995 to 2004} \item[19:30 -- 20:00]{Masquerade Prep} \item[20:00 -- 23:59]{Masquerade}\end{description} \newpage \thispagestyle{empty} \section*{Thursday -- Pilbara (Video Game Stream)}\begin{description} \Large \item[09:00 -- 10:00]{Open Console Gaming} \item[10:00 -- 13:00]{Blur} \item[14:00 -- 15:30]{DS Fun-o-rama} \item[15:30 -- 17:00]{Soul Caliber 4 \& 5} \item[17:00 -- 18:00]{Scott Pilgrim VS The World The Game Co-op Bananza!} \item[19:30 -- 23:30]{Left 4 Dead 1 and 2 - Survival Endurance Marathon}\end{description} \newpage \thispagestyle{empty} \section*{Thursday -- North Hamersley (Gaming and Others)}\begin{description} \Large \item[10:00 -- 11:00]{Introduction to Modern Board games - what is all the fuss about?} \item[12:00 -- 13:00]{The Fiction Factory: Speculative Fiction and Professional Publishing} \item[14:00 -- 14:30]{Launch - Leonie Rogers - "Frontier Resistance"} \item[14:30 -- 15:00]{Launch - Louisa Loder - "Stormfate"} \item[15:00 -- 16:00]{WA Writers' Panel} \item[16:00 -- 17:00]{UggTect Royale - The Second Clubbing} \item[17:00 -- 18:00]{Crits and Grits - When Are Crit Groups A Good Idea?} \item[21:30 -- 23:00]{Under Construction - Marketing}\end{description} \newpage \thispagestyle{empty} \section*{Thursday -- Family Room (Boardroom)}\begin{description} \Large \item[09:30 -- 11:00]{Saturday Morning Cartoons} \item[11:00 -- 11:30]{My Little Pony - Colouring In And Discussion} \item[11:30 -- 12:00]{Cookie Decorating} \item[12:00 -- 13:00]{Children's LARP} \item[14:00 -- 14:30]{Quiet Reading} \item[14:30 -- 15:00]{The Basics of Sewing} \item[15:00 -- 15:30]{Reading 2} \item[15:30 -- 16:30]{Costume Crafting for Kids} \item[16:30 -- 18:00]{Kids Masquerade}\end{description} \newpage \thispagestyle{empty} \section*{Thursday -- South Ballroom (Traders and Art Show Room)}\begin{description} \Large \item[10:00 -- 18:00]{Traders and Art Show}\end{description} \newpage \end{document}
\documentclass[10,a4paperpaper,]{article} \title{Analysis and Forecast of Fish Trade Import and Export \break in Norway using time features with Glmnet and Prophet} \author{Damien Dupré} \date{\today} \newcommand{\logo}{dot_logo.png} \newcommand{\cover}{dcu_cover.png} \newcommand{\iblue}{2b4894} \newcommand{\igray}{d4dbde} \usepackage{ragged2e} \include{defs} \begin{document} \renewcommand{\contentsname}{Analysis and Forecast of Fish Trade Import and Export in Norway} \renewcommand{\pagename}{Page} \maketitle \tableofcontents \addcontentsline{toc}{section}{Contents} \clearpage \justifying \section{Introduction} This report investigate the evolution of fish unit price and implement algorithm to forecast this evolution. Each chapter is dedicated to a specific fish trade analysis which involves a type of fish, a country and its type of trade (import or export). Within these chapters, a first section is dedicated to the analysis of the trade history using classic methods and visualisations. A second section is dedicated to the implementation of forecast algorithms. Currently, 2 different forecast algorithm models are implemented: Glmnet and Prophet. \begin{itemize} \item Glmnet is a generalized linear model via penalized maximum likelihood trained for forecast purpose. The regularization path is computed for the lasso or elasticnet penalty at a grid of values for the regularization parameter lambda. The algorithm is extremely fast, and can exploit sparsity in the input matrix \(x\). \item Prophet is a procedure for forecasting time series data based on an additive model where non-linear trends are fit with yearly, weekly, and daily seasonality, plus holiday effects. It works best with time series that have strong seasonal effects and several seasons of historical data. Prophet is robust to missing data and shifts in the trend, and typically handles outliers well. \end{itemize} Finally additional analyses are presented in order to focus on specific points of the analysis such as factors influencing the Unit Price evolution, Seasonality and Trade evolution of specific partners. \clearpage \section{Horse Mackerel and Scomber Exports from Norway} \subsection{Analysis} Between 2012 and 2020, Norway has exported horse mackerel to 32 countries worldwide. Data for Scomber are substantially different. Indeed, between 1998 and 2019, Norway has exported Scomber to 108 countries worldwide. The data collected shows a important discrepancy between these countries regarding the trade history, the level of the price applied and its volatility. \includegraphics{report_files/figure-latex/unnamed-chunk-1-1.pdf} In the Figure here above, it is possible to distinguish two different patterns for Horse Mackerel and Scomber fish exports. For Horse Mackerel trades, countries with a high average price and high volatility such as Lithuania, high average price and low volatility such as France, low average price and high volatility such as Denmark and low average price with low volatility such as Egypt. A second factor is particularly important to take into account, the level of trade can vary between the countries. Some countries have only one or two trades while others have more than 60 trades. For Scomber, the lower Unit Price of the trade is the less volatility there is expect for Mexico, Qatar and India but these countries have only one trade and can be considered as outliers. It is interesting to observe that the number of transaction according the countries does not influence the average unit price. \includegraphics{report_files/figure-latex/unnamed-chunk-2-1.pdf} The world map representations are summaries of the pointrange/bar plot visualisation of the export trades. The red colour indicates the number of trades (dark red means important trade history) while the blue dot indicates the volatility in the trade (light blue means high volatility). This representation show that there are significant discrepancies between the export countries regardless their distance from Norway or their continent. Despite these significant differences between trade partners, for the forecast models done in the next sections this bias will not be removed as all the data will be taken into account. The available data are too low in term of sampling frequency (once a month maximum), on a too short period, with not enough data per country. Therefore an analysis country wise is impossible. All the data will be taken into account in the coming sections. \includegraphics{report_files/figure-latex/unnamed-chunk-3-1.pdf} The trend of the evolution of Horse Mackerel unit price since 2012 indicates following a slight parabolic inverse trend with a valley (negative peak) in 2016 whereas the trend of the evolution of Scomber unit price since 1998 indicates following a slight parabolic normal trend with a peak around 2010. \subsection{Glmnet Algorithm Forecast} In order to forecast the evolution of fish price according the time, the existing data are split in two sections: the train region which will be used to build the forecast model and the test region which will be used compare the data predicted with the actual data. In order to process this forecasting model, 224 time features are extracted and used to predict the evolution of the Horse Mackerel unit price and 224 time features are extracted and used to predict the evolution of the Scomber unit price. By selecting a test region corresponding to the last two years (i.e., from 2018 to 2020), it is possible to compare the forecast accuracy with the actual Average unit price values. The most used indicators are \(RMSE\) and \(MAE\). Root Mean Square Error (RMSE) is the standard deviation of the residuals (prediction errors). Residuals are a measure of how far from the regression line data points are; RMSE is a measure of how spread out these residuals are. In other words, it tells you how concentrated the data is around the line of best fit. Mean Absolute Error (MAE) is a measure of errors between paired observations expressing the same phenomenon. This is known as a scale-dependent accuracy measure and therefore cannot be used to make comparisons between series using different scales. The closer to 0 is the \(RMSE\) and \(MAE\) value, the better. In parallel, the \(R^2\) indicator also ranges from 0 to 1 but the closer to 1 is the value, the better. Here, for Horse Mackerel unit price prediction: \(RMSE_{hm} =\) 0.47 and \(MAE_{hm} =\) 0.43. These results are encouraging but could be largely be improved. The model explains \(R^2_{hm} =\) 3\% of the variance of the Horse Mackerel unit price variation. For the Scomber unit price prediction: \(RMSE_{sc} =\) 0.64 and \(MAE_{sc} =\) 0.6. These results are not as good as those for the Horse Mackerel and is explain by the amount of data available and their larger variability. The model explains \(R^2_{sc} =\) 2\% of the variance of the Scomber unit price variation. Based on the model previously test, a forecast of the 24 next months is performed. Even if the accuracy of the forecast model on the test table is low, it is still possible to use it to forecast the price within 2 years. \includegraphics{report_files/figure-latex/unnamed-chunk-5-1.pdf} In the case of the Horse Mackerel unit price prediction, The model reveals a sharp decrease in 2020 and a rebound from 2021 followed by a stabilization of the prices at \$1.60. \includegraphics{report_files/figure-latex/unnamed-chunk-6-1.pdf} In the case of the Scomber unit price prediction, The model reveals a moderate decrease in 2020 and a rebound from 2021. \subsection{Prophet Algorithm Forecast} As the glmnet algorithm, the prophet decomposition extract the temporal trends, seasonality, multiplicative factor and their prediction residuals. \includegraphics{report_files/figure-latex/unnamed-chunk-7-1.pdf} In term of algorithm validation \(RMSE\) and \(MAE\) can be calculated from the original data. For Horse Mackerel prediction, \(RMSE_{hm} =\) 0.57 and \(MAE_{hm} =\) 0.54, which is better than the glmnet algorithm. For Scomber prediction, \(RMSE_{sc} =\) 0.39 and \(MAE_{sc} =\) 0.32. The result of the forecast by Prophet uses the seasonality of the price evolution (see Additional Analyses section) as well as the overall trend. \includegraphics{report_files/figure-latex/unnamed-chunk-9-1.pdf} For Horse Mackerel, the prediction reveals a decrease of the fish price from February to November with a price in 2022 slightly higher than 2021. \includegraphics{report_files/figure-latex/unnamed-chunk-10-1.pdf} For Scomber, the prediction reveals a decrease of the fish price until 2022 with seasonal changes. \subsection{Additional Analyses} The difference between countries that are historic and recurrent trade partner with countries who have only several past trade is highly relevant. Indeed we can imagine that price establishment is build on a commercial relationship between the countries, if a country has no history, the average price paid is likely to be higher than historical trade partners which will bias the forecast of the evolution. \includegraphics{report_files/figure-latex/unnamed-chunk-11-1.pdf} However the results show that the number of trade has no significant relationship with the average unit price of Horse Mackerel trade (\(R^2 = .07\), \(F(1, 30) = 2.12\), \(p = .156\)) and Scomber trade (\(R^2 = < .01\), \(F(1, 106) = 0.44\), \(p = .509\)). \includegraphics{report_files/figure-latex/unnamed-chunk-12-1.pdf} Another possible bias involved in trade relationship is the possible relationship between quantity and unit price. It seems logical to believe that countries buying more will have more leverage to negotiate their unit price. The results reveals a weak but significant relationship between the unit quantity ordered on a log scale and Horse Mackerel unit price (\(R^2 = .02\), \(F(1, 366) = 5.68\), \(p = .018\)) as well as Scomber unit price (\(R^2 = .07\), \(F(1, 9268) = 734.25\), \(p < .001\)). A future investigation would be to try to understand the factors explaining why certain countries have a high average price and others a low average price (beside the the number of trade). \clearpage \section{Horse Mackerel and Scomber Imports by Norway} \subsection{Analysis} Between 2012 and 2019, Norway has imported Horse Mackerel from 9 countries worldwide. Data for Scomber are substantially different. Indeed, between 1999 and 2020, Norway has imported Scomber from 26 countries worldwide. Similarly as the export, the data collected shows a important discrepancy between these countries regarding the trade history, the level of the price applied and its volatility. \includegraphics{report_files/figure-latex/unnamed-chunk-13-1.pdf} For Horse Mackerel trades, countries with a high average price and high volatility such as Turkey, Vietnam and the Netherlands, high average price and low volatility such as Spain and Germany, low average price and high volatility such as Ireland and low average price with low volatility such as the United Kingdom. In a similar way as the export of Horse Mackerel, the level of trade can vary between the countries and is particularly important to take into account. Some countries have only one or two trades while others have more than 20 trades. For Scomber, it is possible to identify the same pattern: - high price/ high volatility (such as Vietnam) - high price/ low volatility (such as Belgium and Morocco) - low price/ high volatility (such as the United States) - low price/ low volatility (such as Jordan and Romania) \includegraphics{report_files/figure-latex/unnamed-chunk-14-1.pdf} The world map representations are summaries of the pointrange/bar plot visualisation of the import trades. The red colour indicates the number of trades (dark red means important trade history) while the blue dot indicates the volatility in the trade (light blue means high volatility). This representation show that there are significant discrepancies between the type of fish in term of country partner and trading history. In a similar way as it has been done for the export forecast, all the data will be taken into account in the coming sections. Specific effects and characteristic of countries will not be taken into account and an average unit price per month is applied for the overall trade partners. \includegraphics{report_files/figure-latex/unnamed-chunk-15-1.pdf} The trend of the evolution of Horse Mackerel unit price since 2012 indicates a slow but continuous decrease whereas the trend of the evolution of Scomber unit price since 1999 increased since 2000 and are now stabilized with a slight decrease. \subsection{Glmnet Algorithm Forecast} In order to forecast the evolution of fish price according the time, the existing data are split in two sections: the train region which will be used to build the forecast model and the test region which will be used compare the data predicted with the actual data. In order to process this forecasting model, 224 time features are extracted and used to predict the evolution of the Horse Mackerel unit price and 224 time features are extracted and used to predict the evolution of the Scomber unit price. By selecting a test region corresponding to the last two years (i.e., from 2018 to 2020), it is possible to compare the forecast accuracy with the actual Average unit price values. The most used indicators are \(RMSE\) and \(MAE\). Root Mean Square Error (RMSE) is the standard deviation of the residuals (prediction errors). Residuals are a measure of how far from the regression line data points are; RMSE is a measure of how spread out these residuals are. In other words, it tells you how concentrated the data is around the line of best fit. Mean Absolute Error (MAE) is a measure of errors between paired observations expressing the same phenomenon. This is known as a scale-dependent accuracy measure and therefore cannot be used to make comparisons between series using different scales. The closer to 0 is the \(RMSE\) and \(MAE\) value, the better. In parallel, the \(R^2\) indicator also ranges from 0 to 1 but the closer to 1 is the value, the better. Here, for Horse Mackerel unit price prediction: \(RMSE_{hm} =\) 1.03 and \(MAE_{hm} =\) 0.8. These results reveals that this prediction could be largely be improved. The differences between the months make this prediction model very difficult to establish. The model explains \(R^2_{hm} =\) 3\% of the variance of the Horse Mackerel unit price variation. For the Scomber unit price prediction: \(RMSE_{sc} =\) 1.52 and \(MAE_{sc} =\) 1.04. These results are once again not as good as those for the Horse Mackerel. The trading of Scomber appear to be particularly difficult. The model explains \(R^2_{sc} =\) 2\% of the variance of the Scomber unit price variation. Based on the model previously test, a forecast of the 24 next months is performed. Even if the accuracy of the forecast model on the test table is low, it is still possible to use it to forecast the price within 2 years. \includegraphics{report_files/figure-latex/unnamed-chunk-17-1.pdf} In the case of the Horse Mackerel unit price prediction, The model reveals a slow decrease until 2024 followed by a rebound. \includegraphics{report_files/figure-latex/unnamed-chunk-18-1.pdf} In the case of the Scomber unit price prediction, The model reveals a as significant increase in first 6 months of 2020 and a continuous decrease until 2022. \subsection{Prophet Algorithm Forecast} As the glmnet algorithm, the prophet decomposition extract the temporal trends, seasonality, multiplicative factor and their prediction residuals. \includegraphics{report_files/figure-latex/unnamed-chunk-19-1.pdf} In term of algorithm validation \(RMSE\) and \(MAE\) can be calculated from the original data. For Horse Mackerel prediction, \(RMSE_{hm} =\) 1.18 and \(MAE_{hm} =\) 0.78, which is not as good as the glmnet algorithm. For Scomber prediction, \(RMSE_{sc} =\) 1.73 and \(MAE_{sc} =\) 1.53 which is again higher than those from the glmnet algorithm. The result of the forecast by Prophet uses the seasonality of the price evolution (see Additional Analyses section) as well as the overall trend. \includegraphics{report_files/figure-latex/unnamed-chunk-21-1.pdf} For Horse Mackerel, the prediction reveals a high seasonal effect with a stationary trend. \includegraphics{report_files/figure-latex/unnamed-chunk-22-1.pdf} For Scomber, the prediction reveals a high seasonality effect as well but the trend shows a significant increase according the time. \subsection{Additional Analyses} A linear regression was performed between the average unit price and the number of transaction with a trade partner for Horse Mackerel and Scomber in order to highlight possible factors to be taken into account. \includegraphics{report_files/figure-latex/unnamed-chunk-23-1.pdf} However the results show that the number of trade has no significant relationship with the average unit price of Horse Mackerel trade (\(R^2 = < .01\), \(F(1, 7) = 0.02\), \(p = .880\)) and Scomber trade (\(R^2 = < .01\), \(F(1, 24) = 0.05\), \(p = .818\)). Another possible bias involved in trade relationship is the possible relationship between quantity and unit price. \includegraphics{report_files/figure-latex/unnamed-chunk-24-1.pdf} Interestingly, the results reveals a non significant relationship between the unit price and the the quantity traded for Horse Mackerel (\(R^2 = .04\), \(F(1, 40) = 1.73\), \(p = .196\)) but as strong and significant relationship between the unit price and the the quantity traded for Scomber (\(R^2 = .42\), \(F(1, 187) = 133.41\), \(p < .001\)). This last results reveals the important differences in the trade of this two different fishes. \clearpage \section{Conclusion} In the previous sections of this document have been presented the analysis and forecast of Horse Mackerel and Scomber unit price in export and import trades by Norway. The analysis of this evolutions reveals similarities between the fishes and between the types of trade (i.e.~export vs.~import). The analysis also revealed the differences between the trade partners in term of trade history and their negotiated unit price (specific averages and volatility indexes). For the purpose of this forecast analysis an average unit price per month was calculated in order to remove the influence of trade history between the different partners. In order to forecast the evolution of Horse Mackerel and Scomber unit price in export and import trades by Norway, two specific algorithm were applied: Glmnet and Prophet. These algorithms were using time features and properties of the time series to perform this forecasting according the time. Through some visualisations, the forecast of the unit price over 24 months was revealed. In addition to the forecast, validity indicators were calculated. As this report is a presentation of preliminary results of this forecasting work, these indicators revealed the necessity to improve the validity of this forecast. However, this results is not surprising as the building of forecasting models to predict high volatility financial time-series requires years to build as well as infrastructures and findings. Beside the necessity for more time in the exploration of suitable algorithms and factors to take into account, this analysis could be improved by increasing the quality of the data used (time span, time resolution, trading partner network, type of fishes) and by increasing the processing power in the analysis (increase of features and variable to take into account). Despite these limitations, this report has highlight the possibility to built forecasting models a minima and built established a framework for future improvements. \end{document}
\documentclass{article} \usepackage{fullpage} % Uncomment the config file you want \input{codeListingConfig.tex} \input{juliaMintedConfig.tex} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%% FUN STARTS HERE!!! %%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{document} \section{Experiment} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% This is the experiment. The first is Listing, the second is Minted. % Listing Output \juliaFile{leastSquares} % Minted Output \begin{listing}[h!] \caption{Script \emph{leastSquares}} \label{code:myLabel} \juliaFileMinted{leastSquares.jl} \end{listing} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%% WE ARE DONE !!! %%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \end{document}
% Default to the notebook output style % Inherit from the specified cell style. \documentclass[11pt]{article} \usepackage[T1]{fontenc} % Nicer default font (+ math font) than Computer Modern for most use cases \usepackage{mathpazo} % Basic figure setup, for now with no caption control since it's done % automatically by Pandoc (which extracts ![](path) syntax from Markdown). \usepackage{graphicx} % We will generate all images so they have a width \maxwidth. This means % that they will get their normal width if they fit onto the page, but % are scaled down if they would overflow the margins. \makeatletter \def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth \else\Gin@nat@width\fi} \makeatother \let\Oldincludegraphics\includegraphics % Set max figure width to be 80% of text width, for now hardcoded. \renewcommand{\includegraphics}[1]{\Oldincludegraphics[width=.8\maxwidth]{#1}} % Ensure that by default, figures have no caption (until we provide a % proper Figure object with a Caption API and a way to capture that % in the conversion process - todo). \usepackage{caption} \DeclareCaptionLabelFormat{nolabel}{} \captionsetup{labelformat=nolabel} \usepackage{adjustbox} % Used to constrain images to a maximum size \usepackage{xcolor} % Allow colors to be defined \usepackage{enumerate} % Needed for markdown enumerations to work \usepackage{geometry} % Used to adjust the document margins \usepackage{amsmath} % Equations \usepackage{amssymb} % Equations \usepackage{textcomp} % defines textquotesingle % Hack from http://tex.stackexchange.com/a/47451/13684: \AtBeginDocument{% \def\PYZsq{\textquotesingle}% Upright quotes in Pygmentized code } \usepackage{upquote} % Upright quotes for verbatim code \usepackage{eurosym} % defines \euro \usepackage[mathletters]{ucs} % Extended unicode (utf-8) support \usepackage[utf8x]{inputenc} % Allow utf-8 characters in the tex document \usepackage{fancyvrb} % verbatim replacement that allows latex \usepackage{grffile} % extends the file name processing of package graphics % to support a larger range % The hyperref package gives us a pdf with properly built % internal navigation ('pdf bookmarks' for the table of contents, % internal cross-reference links, web links for URLs, etc.) \usepackage{hyperref} \usepackage{longtable} % longtable support required by pandoc >1.10 \usepackage{booktabs} % table support for pandoc > 1.12.2 \usepackage[inline]{enumitem} % IRkernel/repr support (it uses the enumerate* environment) \usepackage[normalem]{ulem} % ulem is needed to support strikethroughs (\sout) % normalem makes italics be italics, not underlines % Colors for the hyperref package \definecolor{urlcolor}{rgb}{0,.145,.698} \definecolor{linkcolor}{rgb}{.71,0.21,0.01} \definecolor{citecolor}{rgb}{.12,.54,.11} % ANSI colors \definecolor{ansi-black}{HTML}{3E424D} \definecolor{ansi-black-intense}{HTML}{282C36} \definecolor{ansi-red}{HTML}{E75C58} \definecolor{ansi-red-intense}{HTML}{B22B31} \definecolor{ansi-green}{HTML}{00A250} \definecolor{ansi-green-intense}{HTML}{007427} \definecolor{ansi-yellow}{HTML}{DDB62B} \definecolor{ansi-yellow-intense}{HTML}{B27D12} \definecolor{ansi-blue}{HTML}{208FFB} \definecolor{ansi-blue-intense}{HTML}{0065CA} \definecolor{ansi-magenta}{HTML}{D160C4} \definecolor{ansi-magenta-intense}{HTML}{A03196} \definecolor{ansi-cyan}{HTML}{60C6C8} \definecolor{ansi-cyan-intense}{HTML}{258F8F} \definecolor{ansi-white}{HTML}{C5C1B4} \definecolor{ansi-white-intense}{HTML}{A1A6B2} % commands and environments needed by pandoc snippets % extracted from the output of `pandoc -s` \providecommand{\tightlist}{% \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}} \DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}} % Add ',fontsize=\small' for more characters per line \newenvironment{Shaded}{}{} \newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{\textbf{{#1}}}} \newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.56,0.13,0.00}{{#1}}} \newcommand{\DecValTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{{#1}}} \newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{{#1}}} \newcommand{\FloatTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{{#1}}} \newcommand{\CharTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}} \newcommand{\StringTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}} \newcommand{\CommentTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textit{{#1}}}} \newcommand{\OtherTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{{#1}}} \newcommand{\AlertTok}[1]{\textcolor[rgb]{1.00,0.00,0.00}{\textbf{{#1}}}} \newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.02,0.16,0.49}{{#1}}} \newcommand{\RegionMarkerTok}[1]{{#1}} \newcommand{\ErrorTok}[1]{\textcolor[rgb]{1.00,0.00,0.00}{\textbf{{#1}}}} \newcommand{\NormalTok}[1]{{#1}} % Additional commands for more recent versions of Pandoc \newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.53,0.00,0.00}{{#1}}} \newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}} \newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}} \newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.73,0.40,0.53}{{#1}}} \newcommand{\ImportTok}[1]{{#1}} \newcommand{\DocumentationTok}[1]{\textcolor[rgb]{0.73,0.13,0.13}{\textit{{#1}}}} \newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{{#1}}}}} \newcommand{\CommentVarTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{{#1}}}}} \newcommand{\VariableTok}[1]{\textcolor[rgb]{0.10,0.09,0.49}{{#1}}} \newcommand{\ControlFlowTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{\textbf{{#1}}}} \newcommand{\OperatorTok}[1]{\textcolor[rgb]{0.40,0.40,0.40}{{#1}}} \newcommand{\BuiltInTok}[1]{{#1}} \newcommand{\ExtensionTok}[1]{{#1}} \newcommand{\PreprocessorTok}[1]{\textcolor[rgb]{0.74,0.48,0.00}{{#1}}} \newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.49,0.56,0.16}{{#1}}} \newcommand{\InformationTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{{#1}}}}} \newcommand{\WarningTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{{#1}}}}} % Define a nice break command that doesn't care if a line doesn't already % exist. \def\br{\hspace*{\fill} \\* } % Math Jax compatability definitions \def\gt{>} \def\lt{<} % Document parameters \title{Task 1} % Pygments definitions \makeatletter \def\PY@reset{\let\PY@it=\relax \let\PY@bf=\relax% \let\PY@ul=\relax \let\PY@tc=\relax% \let\PY@bc=\relax \let\PY@ff=\relax} \def\PY@tok#1{\csname PY@tok@#1\endcsname} \def\PY@toks#1+{\ifx\relax#1\empty\else% \PY@tok{#1}\expandafter\PY@toks\fi} \def\PY@do#1{\PY@bc{\PY@tc{\PY@ul{% \PY@it{\PY@bf{\PY@ff{#1}}}}}}} \def\PY#1#2{\PY@reset\PY@toks#1+\relax+\PY@do{#2}} \expandafter\def\csname PY@tok@w\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.73,0.73}{##1}}} \expandafter\def\csname PY@tok@c\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}} \expandafter\def\csname PY@tok@cp\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.74,0.48,0.00}{##1}}} \expandafter\def\csname PY@tok@k\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} \expandafter\def\csname PY@tok@kp\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} \expandafter\def\csname PY@tok@kt\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.69,0.00,0.25}{##1}}} \expandafter\def\csname PY@tok@o\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} \expandafter\def\csname PY@tok@ow\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.67,0.13,1.00}{##1}}} \expandafter\def\csname PY@tok@nb\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} \expandafter\def\csname PY@tok@nf\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}} \expandafter\def\csname PY@tok@nc\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}} \expandafter\def\csname PY@tok@nn\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}} \expandafter\def\csname PY@tok@ne\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.82,0.25,0.23}{##1}}} \expandafter\def\csname PY@tok@nv\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} \expandafter\def\csname PY@tok@no\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.53,0.00,0.00}{##1}}} \expandafter\def\csname PY@tok@nl\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.63,0.63,0.00}{##1}}} \expandafter\def\csname PY@tok@ni\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.60,0.60,0.60}{##1}}} \expandafter\def\csname PY@tok@na\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.49,0.56,0.16}{##1}}} \expandafter\def\csname PY@tok@nt\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} \expandafter\def\csname PY@tok@nd\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.67,0.13,1.00}{##1}}} \expandafter\def\csname PY@tok@s\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} \expandafter\def\csname PY@tok@sd\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} \expandafter\def\csname PY@tok@si\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.73,0.40,0.53}{##1}}} \expandafter\def\csname PY@tok@se\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.73,0.40,0.13}{##1}}} \expandafter\def\csname PY@tok@sr\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.40,0.53}{##1}}} \expandafter\def\csname PY@tok@ss\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} \expandafter\def\csname PY@tok@sx\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} \expandafter\def\csname PY@tok@m\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} \expandafter\def\csname PY@tok@gh\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,0.50}{##1}}} \expandafter\def\csname PY@tok@gu\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.50,0.00,0.50}{##1}}} \expandafter\def\csname PY@tok@gd\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.63,0.00,0.00}{##1}}} \expandafter\def\csname PY@tok@gi\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.63,0.00}{##1}}} \expandafter\def\csname PY@tok@gr\endcsname{\def\PY@tc##1{\textcolor[rgb]{1.00,0.00,0.00}{##1}}} \expandafter\def\csname PY@tok@ge\endcsname{\let\PY@it=\textit} \expandafter\def\csname PY@tok@gs\endcsname{\let\PY@bf=\textbf} \expandafter\def\csname PY@tok@gp\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,0.50}{##1}}} \expandafter\def\csname PY@tok@go\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.53,0.53,0.53}{##1}}} \expandafter\def\csname PY@tok@gt\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.27,0.87}{##1}}} \expandafter\def\csname PY@tok@err\endcsname{\def\PY@bc##1{\setlength{\fboxsep}{0pt}\fcolorbox[rgb]{1.00,0.00,0.00}{1,1,1}{\strut ##1}}} \expandafter\def\csname PY@tok@kc\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} \expandafter\def\csname PY@tok@kd\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} \expandafter\def\csname PY@tok@kn\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} \expandafter\def\csname PY@tok@kr\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} \expandafter\def\csname PY@tok@bp\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} \expandafter\def\csname PY@tok@fm\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}} \expandafter\def\csname PY@tok@vc\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} \expandafter\def\csname PY@tok@vg\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} \expandafter\def\csname PY@tok@vi\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} \expandafter\def\csname PY@tok@vm\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} \expandafter\def\csname PY@tok@sa\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} \expandafter\def\csname PY@tok@sb\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} \expandafter\def\csname PY@tok@sc\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} \expandafter\def\csname PY@tok@dl\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} \expandafter\def\csname PY@tok@s2\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} \expandafter\def\csname PY@tok@sh\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} \expandafter\def\csname PY@tok@s1\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} \expandafter\def\csname PY@tok@mb\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} \expandafter\def\csname PY@tok@mf\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} \expandafter\def\csname PY@tok@mh\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} \expandafter\def\csname PY@tok@mi\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} \expandafter\def\csname PY@tok@il\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} \expandafter\def\csname PY@tok@mo\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} \expandafter\def\csname PY@tok@ch\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}} \expandafter\def\csname PY@tok@cm\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}} \expandafter\def\csname PY@tok@cpf\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}} \expandafter\def\csname PY@tok@c1\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}} \expandafter\def\csname PY@tok@cs\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}} \def\PYZbs{\char`\\} \def\PYZus{\char`\_} \def\PYZob{\char`\{} \def\PYZcb{\char`\}} \def\PYZca{\char`\^} \def\PYZam{\char`\&} \def\PYZlt{\char`\<} \def\PYZgt{\char`\>} \def\PYZsh{\char`\#} \def\PYZpc{\char`\%} \def\PYZdl{\char`\$} \def\PYZhy{\char`\-} \def\PYZsq{\char`\'} \def\PYZdq{\char`\"} \def\PYZti{\char`\~} % for compatibility with earlier versions \def\PYZat{@} \def\PYZlb{[} \def\PYZrb{]} \makeatother % Exact colors from NB \definecolor{incolor}{rgb}{0.0, 0.0, 0.5} \definecolor{outcolor}{rgb}{0.545, 0.0, 0.0} % Prevent overflowing lines due to hard-to-break entities \sloppy % Setup hyperref package \hypersetup{ breaklinks=true, % so long urls are correctly broken across lines colorlinks=true, urlcolor=urlcolor, linkcolor=linkcolor, citecolor=citecolor, } % Slightly bigger margins than the latex defaults \geometry{verbose,tmargin=1in,bmargin=1in,lmargin=1in,rmargin=1in} \begin{document} \maketitle \begin{Verbatim}[commandchars=\\\{\}] {\color{incolor}In [{\color{incolor}1}]:} \PY{k+kn}{import} \PY{n+nn}{pandas} \PY{k}{as} \PY{n+nn}{pd} \PY{k+kn}{import} \PY{n+nn}{numpy} \PY{k}{as} \PY{n+nn}{np} \PY{k+kn}{import} \PY{n+nn}{networkx} \PY{k}{as} \PY{n+nn}{nx} \end{Verbatim} \hypertarget{load-and-clean-corpus}{% \section{Load and Clean corpus}\label{load-and-clean-corpus}} Load the corpus and introduce two additional states * \textless{} S \textgreater{} \ldots{} the beginning of a setence * \textless{} E \textgreater{} \ldots{} the end of a setence \begin{Verbatim}[commandchars=\\\{\}] {\color{incolor}In [{\color{incolor}184}]:} \PY{k}{with} \PY{n+nb}{open}\PY{p}{(}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{corpus.txt}\PY{l+s+s1}{\PYZsq{}}\PY{p}{)} \PY{k}{as} \PY{n}{f}\PY{p}{:} \PY{n}{corpus\PYZus{}raw} \PY{o}{=} \PY{n}{f}\PY{o}{.}\PY{n}{readlines}\PY{p}{(}\PY{p}{)} \PY{n}{corpus\PYZus{}clean} \PY{o}{=} \PY{p}{[}\PY{p}{]} \PY{k}{for} \PY{n}{l} \PY{o+ow}{in} \PY{n}{corpus\PYZus{}raw}\PY{p}{:} \PY{c+c1}{\PYZsh{} Remove newline symbole} \PY{k}{if} \PY{n}{l}\PY{p}{[}\PY{o}{\PYZhy{}}\PY{l+m+mi}{1}\PY{p}{]} \PY{o}{==} \PY{l+s+s1}{\PYZsq{}}\PY{l+s+se}{\PYZbs{}n}\PY{l+s+s1}{\PYZsq{}}\PY{p}{:} \PY{n}{l} \PY{o}{=} \PY{n}{l}\PY{p}{[}\PY{p}{:}\PY{o}{\PYZhy{}}\PY{l+m+mi}{1}\PY{p}{]} \PY{c+c1}{\PYZsh{} Remove empty lines} \PY{k}{if} \PY{n}{l} \PY{o}{==} \PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{\PYZsq{}}\PY{p}{:} \PY{k}{continue} \PY{c+c1}{\PYZsh{} Remove end of line} \PY{k}{if} \PY{n}{l}\PY{o}{.}\PY{n}{startswith}\PY{p}{(}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{\PYZlt{}}\PY{l+s+s1}{\PYZsq{}}\PY{p}{)}\PY{p}{:} \PY{k}{continue} \PY{n}{corpus\PYZus{}clean}\PY{o}{.}\PY{n}{append}\PY{p}{(}\PY{n}{l}\PY{o}{.}\PY{n}{split}\PY{p}{(}\PY{p}{)}\PY{p}{)} \PY{c+c1}{\PYZsh{} Add artifical setence end and start after .} \PY{k}{if} \PY{n}{l} \PY{o}{==} \PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{. . Fp 0}\PY{l+s+s1}{\PYZsq{}}\PY{p}{:} \PY{n}{corpus\PYZus{}clean}\PY{o}{.}\PY{n}{append}\PY{p}{(}\PY{p}{[}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{\PYZlt{}E\PYZgt{}}\PY{l+s+s1}{\PYZsq{}}\PY{p}{,} \PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{\PYZlt{}E\PYZgt{}}\PY{l+s+s1}{\PYZsq{}}\PY{p}{,} \PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{\PYZlt{}E\PYZgt{}}\PY{l+s+s1}{\PYZsq{}}\PY{p}{,} \PY{l+m+mi}{0}\PY{p}{]}\PY{p}{)} \PY{n}{corpus\PYZus{}clean}\PY{o}{.}\PY{n}{append}\PY{p}{(}\PY{p}{[}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{\PYZlt{}S\PYZgt{}}\PY{l+s+s1}{\PYZsq{}}\PY{p}{,} \PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{\PYZlt{}S\PYZgt{}}\PY{l+s+s1}{\PYZsq{}}\PY{p}{,} \PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{\PYZlt{}S\PYZgt{}}\PY{l+s+s1}{\PYZsq{}}\PY{p}{,} \PY{l+m+mi}{0}\PY{p}{]}\PY{p}{)} \PY{c+c1}{\PYZsh{} Add a artificial start at the beginning, and remove last element} \PY{n}{corpus\PYZus{}clean}\PY{o}{.}\PY{n}{insert}\PY{p}{(}\PY{l+m+mi}{0}\PY{p}{,} \PY{p}{[}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{\PYZlt{}S\PYZgt{}}\PY{l+s+s1}{\PYZsq{}}\PY{p}{,} \PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{\PYZlt{}S\PYZgt{}}\PY{l+s+s1}{\PYZsq{}}\PY{p}{,} \PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{\PYZlt{}S\PYZgt{}}\PY{l+s+s1}{\PYZsq{}}\PY{p}{,} \PY{l+m+mi}{0}\PY{p}{]}\PY{p}{)} \PY{n}{corpus\PYZus{}clean}\PY{o}{.}\PY{n}{pop}\PY{p}{(}\PY{p}{)} \PY{n}{corpus\PYZus{}clean}\PY{o}{.}\PY{n}{pop}\PY{p}{(}\PY{p}{)} \PY{c+c1}{\PYZsh{} Convert the corpus into an pandas dataframe} \PY{n}{corpus} \PY{o}{=} \PY{n}{pd}\PY{o}{.}\PY{n}{DataFrame}\PY{p}{(}\PY{n}{data}\PY{o}{=}\PY{n}{corpus\PYZus{}clean}\PY{p}{,} \PY{n}{columns}\PY{o}{=}\PY{p}{[}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{token}\PY{l+s+s1}{\PYZsq{}}\PY{p}{,} \PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{lema}\PY{l+s+s1}{\PYZsq{}}\PY{p}{,} \PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{tag}\PY{l+s+s1}{\PYZsq{}}\PY{p}{,} \PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{content}\PY{l+s+s1}{\PYZsq{}}\PY{p}{]}\PY{p}{)} \PY{n}{corpus}\PY{o}{.}\PY{n}{head}\PY{p}{(}\PY{l+m+mi}{15}\PY{p}{)} \end{Verbatim} \begin{Verbatim}[commandchars=\\\{\}] {\color{outcolor}Out[{\color{outcolor}184}]:} token lema tag content 0 <S> <S> <S> 0 1 Tristana tristana NP00000 0 2 es ser VSIP3S0 01775973 3 una uno DI0FS0 0 4 película película NCFS000 04960631 5 de de SPS00 0 6 el el DA0MS0 0 7 director director NCMS000 07063762 8 español español AQ0MS0 02727705 9 nacionalizado nacionalizar VMP00SM 00285796 10 mexicano mexicano AQ0MS0 02782661 11 Luis\_Buñuel luis\_buñuel NP00000 0 12 . . Fp 0 13 <E> <E> <E> 0 14 <S> <S> <S> 0 \end{Verbatim} \hypertarget{transition-probabilities}{% \section{Transition Probabilities}\label{transition-probabilities}} Use the corpus to calculate transition probabilities between POS tags It is read from \textbf{row} -\textgreater{} \textbf{column} e.g. S -\textgreater{} SPS00 = 0.4 \ldots{} means after the setence start there is a chance of 40\% that the next tag is a SPS00 \begin{Verbatim}[commandchars=\\\{\}] {\color{incolor}In [{\color{incolor}210}]:} \PY{c+c1}{\PYZsh{} Build table to transition probabilities} \PY{n}{tags} \PY{o}{=} \PY{n}{corpus}\PY{p}{[}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{tag}\PY{l+s+s1}{\PYZsq{}}\PY{p}{]} \PY{n}{utags} \PY{o}{=} \PY{n}{tags}\PY{o}{.}\PY{n}{unique}\PY{p}{(}\PY{p}{)} \PY{c+c1}{\PYZsh{} Generate empty table} \PY{n}{tp} \PY{o}{=} \PY{n}{pd}\PY{o}{.}\PY{n}{DataFrame}\PY{p}{(}\PY{n}{columns}\PY{o}{=}\PY{n}{utags}\PY{p}{,} \PY{n}{index}\PY{o}{=}\PY{n}{utags}\PY{p}{,} \PY{n}{data}\PY{o}{=}\PY{l+m+mi}{0}\PY{p}{)} \PY{c+c1}{\PYZsh{} Add transition frequencies} \PY{k}{for} \PY{n}{i}\PY{p}{,} \PY{n}{j} \PY{o+ow}{in} \PY{n+nb}{zip}\PY{p}{(}\PY{n}{tags}\PY{p}{[}\PY{p}{:}\PY{o}{\PYZhy{}}\PY{l+m+mi}{1}\PY{p}{]}\PY{p}{,} \PY{n}{tags}\PY{p}{[}\PY{l+m+mi}{1}\PY{p}{:}\PY{p}{]}\PY{p}{)}\PY{p}{:} \PY{n}{tp}\PY{o}{.}\PY{n}{loc}\PY{p}{[}\PY{n}{i}\PY{p}{,} \PY{n}{j}\PY{p}{]} \PY{o}{=} \PY{n}{tp}\PY{o}{.}\PY{n}{loc}\PY{p}{[}\PY{n}{i}\PY{p}{,} \PY{n}{j}\PY{p}{]} \PY{o}{+} \PY{l+m+mi}{1} \PY{n}{tp}\PY{o}{.}\PY{n}{head}\PY{p}{(}\PY{p}{)} \end{Verbatim} \begin{Verbatim}[commandchars=\\\{\}] {\color{outcolor}Out[{\color{outcolor}210}]:} <S> NP00000 VSIP3S0 DI0FS0 NCFS000 SPS00 DA0MS0 NCMS000 AQ0MS0 VMP00SM Fp <E> VAIP3S0 VMP00SF DA0FS0 VSIS3S0 AQ0CS0 RN AQ0FS0 Z DP3CS0 AO0MS0 CC VMIP3S0 CS VSSP1S0 DI0MS0 Fc VSN0000 PR0CN000 VMN0000 NCMN000 PI0CS000 NCFP000 DD0MS0 NCCS000 Fpa Fpt PR0CP000 PP3CSD00 RG VMIC1S0 DI0FP0 PP3CNA00 Fe P0000000 PR0CS000 DA0MP0 NCMP000 DA0NS0 \textbackslash{} <S> 0 3 0 0 0 6 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 0 0 NP00000 0 0 1 0 0 3 0 0 0 0 4 0 0 0 0 0 0 0 0 0 0 0 2 7 0 0 0 6 0 0 0 0 0 0 0 0 2 3 0 1 0 1 0 0 1 0 0 0 0 0 VSIP3S0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 DI0FS0 0 0 0 0 3 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 NCFS000 0 0 0 0 0 6 0 0 0 0 1 0 0 0 0 0 1 1 1 0 0 0 1 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 VMIP3P0 VMIS3S0 VMII1S0 PI0MS000 Zu VMSP1S0 Fx PP3MS000 VMSI1S0 VAII1S0 DP3CP0 NCCP000 VMG0000 PP3MPA00 DD0CP0 VMP00PM DI0MP0 AQ0MP0 VSII1S0 VMII3P0 <S> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 NP00000 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 VSIP3S0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 DI0FS0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 NCFS000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \end{Verbatim} \hypertarget{normalized-transition-probability-matrix}{% \subsubsection{Normalized transition probability matrix}\label{normalized-transition-probability-matrix}} \begin{Verbatim}[commandchars=\\\{\}] {\color{incolor}In [{\color{incolor}211}]:} \PY{c+c1}{\PYZsh{} Normalize row wise} \PY{n}{ntp} \PY{o}{=} \PY{n}{tp}\PY{o}{.}\PY{n}{div}\PY{p}{(}\PY{n}{tp}\PY{o}{.}\PY{n}{sum}\PY{p}{(}\PY{n}{axis}\PY{o}{=}\PY{l+m+mi}{0}\PY{p}{)}\PY{p}{,} \PY{n}{axis}\PY{o}{=}\PY{l+m+mi}{0}\PY{p}{)} \PY{n}{ntp}\PY{o}{.}\PY{n}{to\PYZus{}csv}\PY{p}{(}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{transition\PYZus{}probabilities.csv}\PY{l+s+s1}{\PYZsq{}}\PY{p}{)} \PY{c+c1}{\PYZsh{} Remove the Transitions from end to start \PYZlt{}E\PYZgt{} \PYZhy{}\PYZgt{} \PYZlt{}S\PYZgt{}} \PY{n}{ntp}\PY{o}{.}\PY{n}{loc}\PY{p}{[}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{\PYZlt{}E\PYZgt{}}\PY{l+s+s1}{\PYZsq{}}\PY{p}{,} \PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{\PYZlt{}S\PYZgt{}}\PY{l+s+s1}{\PYZsq{}}\PY{p}{]} \PY{o}{=} \PY{l+m+mf}{0.0} \PY{n}{ntp}\PY{o}{.}\PY{n}{head}\PY{p}{(}\PY{p}{)} \end{Verbatim} \begin{Verbatim}[commandchars=\\\{\}] {\color{outcolor}Out[{\color{outcolor}211}]:} <S> NP00000 VSIP3S0 DI0FS0 NCFS000 SPS00 DA0MS0 NCMS000 AQ0MS0 VMP00SM Fp <E> VAIP3S0 VMP00SF DA0FS0 VSIS3S0 AQ0CS0 RN AQ0FS0 Z DP3CS0 AO0MS0 CC VMIP3S0 CS VSSP1S0 DI0MS0 Fc VSN0000 PR0CN000 VMN0000 NCMN000 PI0CS000 NCFP000 DD0MS0 NCCS000 Fpa Fpt PR0CP000 PP3CSD00 RG VMIC1S0 DI0FP0 PP3CNA00 Fe \textbackslash{} <S> 0.0 0.2 0.00000 0.000000 0.00 0.40000 0.0 0.0 0.0 0.000000 0.0000 0.0 0.066667 0.0 0.0 0.066667 0.0000 0.0000 0.0000 0.0 0.0 0.0 0.0000 0.066667 0.066667 0.0 0.0 0.0000 0.0 0.0000 0.0 0.0 0.0 0.0 0.0 0.0 0.0000 0.00000 0.0 0.00000 0.200000 0.00000 0.0 0.0000 0.00000 NP00000 0.0 0.0 0.03125 0.000000 0.00 0.09375 0.0 0.0 0.0 0.000000 0.1250 0.0 0.000000 0.0 0.0 0.000000 0.0000 0.0000 0.0000 0.0 0.0 0.0 0.0625 0.218750 0.000000 0.0 0.0 0.1875 0.0 0.0000 0.0 0.0 0.0 0.0 0.0 0.0 0.0625 0.09375 0.0 0.03125 0.000000 0.03125 0.0 0.0000 0.03125 VSIP3S0 0.0 0.0 0.00000 0.333333 0.00 0.00000 0.0 0.0 0.0 0.333333 0.0000 0.0 0.000000 0.0 0.0 0.000000 0.0000 0.0000 0.0000 0.0 0.0 0.0 0.0000 0.000000 0.000000 0.0 0.0 0.0000 0.0 0.0000 0.0 0.0 0.0 0.0 0.0 0.0 0.0000 0.00000 0.0 0.00000 0.333333 0.00000 0.0 0.0000 0.00000 DI0FS0 0.0 0.0 0.00000 0.000000 0.75 0.00000 0.0 0.0 0.0 0.000000 0.0000 0.0 0.000000 0.0 0.0 0.000000 0.2500 0.0000 0.0000 0.0 0.0 0.0 0.0000 0.000000 0.000000 0.0 0.0 0.0000 0.0 0.0000 0.0 0.0 0.0 0.0 0.0 0.0 0.0000 0.00000 0.0 0.00000 0.000000 0.00000 0.0 0.0000 0.00000 NCFS000 0.0 0.0 0.00000 0.000000 0.00 0.37500 0.0 0.0 0.0 0.000000 0.0625 0.0 0.000000 0.0 0.0 0.000000 0.0625 0.0625 0.0625 0.0 0.0 0.0 0.0625 0.000000 0.000000 0.0 0.0 0.0625 0.0 0.0625 0.0 0.0 0.0 0.0 0.0 0.0 0.0000 0.00000 0.0 0.00000 0.000000 0.00000 0.0 0.0625 0.06250 P0000000 PR0CS000 DA0MP0 NCMP000 DA0NS0 VMIP3P0 VMIS3S0 VMII1S0 PI0MS000 Zu VMSP1S0 Fx PP3MS000 VMSI1S0 VAII1S0 DP3CP0 NCCP000 VMG0000 PP3MPA00 DD0CP0 VMP00PM DI0MP0 AQ0MP0 VSII1S0 VMII3P0 <S> 0.0000 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.00000 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 NP00000 0.0000 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.03125 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 VSIP3S0 0.0000 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.00000 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 DI0FS0 0.0000 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.00000 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 NCFS000 0.0625 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.00000 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 \end{Verbatim} \hypertarget{emition-probabilities}{% \section{Emition Probabilities}\label{emition-probabilities}} Generate a table containing the probability that a given token coaccuras with a given word. This is read from columns -\textgreater{} rows: VSIP3S0 -\textgreater{} es : given VSIP3S0 100\% of words are `es' NCPFS00 -\textgreater{} película : given NCPFS00, 12.5\% of words are `película' \begin{Verbatim}[commandchars=\\\{\}] {\color{incolor}In [{\color{incolor}212}]:} \PY{n}{unique\PYZus{}tokens} \PY{o}{=} \PY{n}{corpus}\PY{o}{.}\PY{n}{token}\PY{o}{.}\PY{n}{unique}\PY{p}{(}\PY{p}{)} \PY{c+c1}{\PYZsh{} Create empty emission probability matrix} \PY{n}{ePM} \PY{o}{=} \PY{n}{pd}\PY{o}{.}\PY{n}{DataFrame}\PY{p}{(}\PY{n}{index}\PY{o}{=}\PY{n}{unique\PYZus{}tokens}\PY{p}{,} \PY{n}{columns}\PY{o}{=}\PY{n}{utags}\PY{p}{,} \PY{n}{data}\PY{o}{=}\PY{l+m+mi}{0}\PY{p}{)} \PY{c+c1}{\PYZsh{} Fill emission probability matrix} \PY{k}{for} \PY{n}{token} \PY{o+ow}{in} \PY{n}{unique\PYZus{}tokens}\PY{p}{:} \PY{n}{tags} \PY{o}{=} \PY{n}{corpus}\PY{p}{[}\PY{n}{corpus}\PY{o}{.}\PY{n}{token} \PY{o}{==} \PY{n}{token}\PY{p}{]}\PY{o}{.}\PY{n}{tag}\PY{o}{.}\PY{n}{value\PYZus{}counts}\PY{p}{(}\PY{p}{)} \PY{k}{for} \PY{n}{tag}\PY{p}{,} \PY{n}{n} \PY{o+ow}{in} \PY{n}{tags}\PY{o}{.}\PY{n}{iteritems}\PY{p}{(}\PY{p}{)}\PY{p}{:} \PY{n}{ePM}\PY{o}{.}\PY{n}{loc}\PY{p}{[}\PY{n}{token}\PY{p}{,} \PY{n}{tag}\PY{p}{]} \PY{o}{=} \PY{n}{n} \PY{c+c1}{\PYZsh{} Normalize the matrix column wise} \PY{n}{nePM} \PY{o}{=} \PY{n}{ePM}\PY{o}{.}\PY{n}{div}\PY{p}{(}\PY{n}{ePM}\PY{o}{.}\PY{n}{sum}\PY{p}{(}\PY{n}{axis}\PY{o}{=}\PY{l+m+mi}{0}\PY{p}{)}\PY{p}{,} \PY{n}{axis}\PY{o}{=}\PY{l+m+mi}{1}\PY{p}{)} \end{Verbatim} \begin{Verbatim}[commandchars=\\\{\}] {\color{incolor}In [{\color{incolor}213}]:} \PY{n}{ePM}\PY{o}{.}\PY{n}{to\PYZus{}csv}\PY{p}{(}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{emission\PYZus{}frequencies.csv}\PY{l+s+s1}{\PYZsq{}}\PY{p}{)} \PY{n}{nePM}\PY{o}{.}\PY{n}{to\PYZus{}csv}\PY{p}{(}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{emission\PYZus{}probabilities.csv}\PY{l+s+s1}{\PYZsq{}}\PY{p}{)} \PY{n}{nePM}\PY{o}{.}\PY{n}{head}\PY{p}{(}\PY{l+m+mi}{15}\PY{p}{)} \end{Verbatim} \begin{Verbatim}[commandchars=\\\{\}] {\color{outcolor}Out[{\color{outcolor}213}]:} <S> NP00000 VSIP3S0 DI0FS0 NCFS000 SPS00 DA0MS0 NCMS000 AQ0MS0 VMP00SM Fp <E> VAIP3S0 VMP00SF DA0FS0 VSIS3S0 AQ0CS0 RN AQ0FS0 Z DP3CS0 AO0MS0 CC VMIP3S0 CS VSSP1S0 DI0MS0 Fc VSN0000 PR0CN000 VMN0000 NCMN000 PI0CS000 NCFP000 DD0MS0 NCCS000 Fpa Fpt PR0CP000 PP3CSD00 RG VMIC1S0 DI0FP0 PP3CNA00 Fe P0000000 PR0CS000 DA0MP0 \textbackslash{} <S> 1.0 0.00000 0.0 0.0 0.000 0.000000 0.0 0.000000 0.000000 0.000000 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 Tristana 0.0 0.03125 0.0 0.0 0.000 0.000000 0.0 0.000000 0.000000 0.000000 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 es 0.0 0.00000 1.0 0.0 0.000 0.000000 0.0 0.000000 0.000000 0.000000 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 una 0.0 0.00000 0.0 1.0 0.000 0.000000 0.0 0.000000 0.000000 0.000000 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 película 0.0 0.00000 0.0 0.0 0.125 0.000000 0.0 0.000000 0.000000 0.000000 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 de 0.0 0.00000 0.0 0.0 0.000 0.367647 0.0 0.000000 0.000000 0.000000 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 el 0.0 0.00000 0.0 0.0 0.000 0.000000 1.0 0.000000 0.000000 0.000000 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 director 0.0 0.00000 0.0 0.0 0.000 0.000000 0.0 0.027027 0.000000 0.000000 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 español 0.0 0.00000 0.0 0.0 0.000 0.000000 0.0 0.000000 0.142857 0.000000 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 nacionalizado 0.0 0.00000 0.0 0.0 0.000 0.000000 0.0 0.000000 0.000000 0.111111 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 mexicano 0.0 0.00000 0.0 0.0 0.000 0.000000 0.0 0.000000 0.142857 0.000000 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 Luis\_Buñuel 0.0 0.03125 0.0 0.0 0.000 0.000000 0.0 0.000000 0.000000 0.000000 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 . 0.0 0.00000 0.0 0.0 0.000 0.000000 0.0 0.000000 0.000000 0.000000 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 <E> 0.0 0.00000 0.0 0.0 0.000 0.000000 0.0 0.000000 0.000000 0.000000 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 Está 0.0 0.00000 0.0 0.0 0.000 0.000000 0.0 0.000000 0.000000 0.000000 0.0 0.0 0.5 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 NCMP000 DA0NS0 VMIP3P0 VMIS3S0 VMII1S0 PI0MS000 Zu VMSP1S0 Fx PP3MS000 VMSI1S0 VAII1S0 DP3CP0 NCCP000 VMG0000 PP3MPA00 DD0CP0 VMP00PM DI0MP0 AQ0MP0 VSII1S0 VMII3P0 <S> 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 Tristana 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 es 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 una 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 película 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 de 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 el 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 director 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 español 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 nacionalizado 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 mexicano 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 Luis\_Buñuel 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 . 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 <E> 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 Está 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 \end{Verbatim} \hypertarget{pos-tag-sentence}{% \section{POS Tag sentence}\label{pos-tag-sentence}} Pos Tag the sentence \textbf{Habla de trasplantes con el enfermo grave.} \begin{Verbatim}[commandchars=\\\{\}] {\color{incolor}In [{\color{incolor}214}]:} \PY{c+c1}{\PYZsh{}sentence = \PYZsq{}Habla de trasplantes con el enfermo grave.\PYZsq{}.split()} \PY{c+c1}{\PYZsh{} Modify the sentence in order to fit corpus and nePM table} \PY{n}{sentence} \PY{o}{=} \PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{\PYZlt{}S\PYZgt{} habla de trasplantes con el enfermo grave . \PYZlt{}E\PYZgt{}}\PY{l+s+s1}{\PYZsq{}}\PY{o}{.}\PY{n}{split}\PY{p}{(}\PY{p}{)} \end{Verbatim} \hypertarget{simple-single-max-search}{% \subsection{Simple single max search}\label{simple-single-max-search}} Take the etiquete with the highest chance of corresponding to a word. (not taking into accoutn any world order or transition probability between etiquets) \begin{Verbatim}[commandchars=\\\{\}] {\color{incolor}In [{\color{incolor}215}]:} \PY{n}{pos\PYZus{}tags} \PY{o}{=} \PY{p}{[}\PY{n}{nePM}\PY{o}{.}\PY{n}{loc}\PY{p}{[}\PY{n}{w}\PY{p}{]}\PY{o}{.}\PY{n}{idxmax}\PY{p}{(}\PY{p}{)} \PY{k}{for} \PY{n}{w} \PY{o+ow}{in} \PY{n}{sentence}\PY{p}{]} \PY{n+nb}{print}\PY{p}{(}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{ }\PY{l+s+s1}{\PYZsq{}}\PY{o}{.}\PY{n}{join}\PY{p}{(}\PY{n}{sentence}\PY{p}{)}\PY{p}{)} \PY{n+nb}{print}\PY{p}{(}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+se}{\PYZbs{}n}\PY{l+s+s1}{Becomes ...}\PY{l+s+se}{\PYZbs{}n}\PY{l+s+s1}{\PYZsq{}}\PY{p}{)} \PY{k}{for} \PY{n}{w}\PY{p}{,} \PY{n}{tag} \PY{o+ow}{in} \PY{n+nb}{zip}\PY{p}{(}\PY{n}{sentence}\PY{p}{,} \PY{n}{pos\PYZus{}tags}\PY{p}{)}\PY{p}{:} \PY{n+nb}{print}\PY{p}{(}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+si}{\PYZpc{}s}\PY{l+s+s1}{|}\PY{l+s+si}{\PYZpc{}s}\PY{l+s+s1}{ }\PY{l+s+s1}{\PYZsq{}}\PY{o}{\PYZpc{}} \PY{p}{(}\PY{n}{w}\PY{p}{,} \PY{n}{tag}\PY{p}{)}\PY{p}{,} \PY{n}{end}\PY{o}{=}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{\PYZsq{}}\PY{p}{)} \end{Verbatim} \begin{Verbatim}[commandchars=\\\{\}] <S> habla de trasplantes con el enfermo grave . <E> Becomes {\ldots} <S>|<S> habla|VMIP3S0 de|SPS00 trasplantes|NCMP000 con|SPS00 el|DA0MS0 enfermo|AQ0MS0 grave|AQ0CS0 .|Fp <E>|<E> \end{Verbatim} \hypertarget{viterbi-algoritm}{% \subsection{Viterbi Algoritm}\label{viterbi-algoritm}} \begin{Verbatim}[commandchars=\\\{\}] {\color{incolor}In [{\color{incolor}216}]:} \PY{c+c1}{\PYZsh{} Apply a laplace correction for missing transitions and emittions} \PY{n}{nePM2} \PY{o}{=} \PY{n}{nePM} \PY{o}{+} \PY{l+m+mf}{0.0001} \PY{n}{ntp2} \PY{o}{=} \PY{n}{ntp} \PY{o}{+} \PY{l+m+mf}{0.0001} \PY{n}{table} \PY{o}{=} \PY{p}{[}\PY{p}{[}\PY{p}{(}\PY{o}{\PYZhy{}}\PY{n}{np}\PY{o}{.}\PY{n}{log}\PY{p}{(}\PY{l+m+mf}{1.0}\PY{p}{)}\PY{p}{,} \PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{\PYZlt{}S\PYZgt{}}\PY{l+s+s1}{\PYZsq{}}\PY{p}{,} \PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{\PYZsq{}}\PY{p}{)}\PY{p}{]}\PY{p}{,}\PY{p}{]} \PY{k}{for} \PY{n}{w} \PY{o+ow}{in} \PY{n}{sentence}\PY{p}{[}\PY{l+m+mi}{1}\PY{p}{:}\PY{p}{]}\PY{p}{:} \PY{n}{token\PYZus{}emp} \PY{o}{=} \PY{n}{np}\PY{o}{.}\PY{n}{log}\PY{p}{(}\PY{n}{nePM2}\PY{o}{.}\PY{n}{loc}\PY{p}{[}\PY{n}{w}\PY{p}{]}\PY{p}{)} \PY{n}{prev\PYZus{}tags} \PY{o}{=} \PY{n}{table}\PY{p}{[}\PY{o}{\PYZhy{}}\PY{l+m+mi}{1}\PY{p}{]} \PY{n}{next\PYZus{}table} \PY{o}{=} \PY{p}{[}\PY{p}{]} \PY{c+c1}{\PYZsh{} For each next tag, calculate its prop for the previous onces} \PY{k}{for} \PY{n}{next\PYZus{}tag} \PY{o+ow}{in} \PY{n}{token\PYZus{}emp}\PY{o}{.}\PY{n}{index}\PY{o}{.}\PY{n}{values}\PY{p}{:} \PY{n}{prev\PYZus{}table} \PY{o}{=} \PY{p}{[}\PY{p}{]} \PY{k}{for} \PY{n}{prev\PYZus{}tag\PYZus{}p}\PY{p}{,} \PY{n}{prev\PYZus{}tag}\PY{p}{,} \PY{n}{\PYZus{}} \PY{o+ow}{in} \PY{n}{prev\PYZus{}tags}\PY{p}{:} \PY{c+c1}{\PYZsh{} transition prop} \PY{n}{tp} \PY{o}{=} \PY{n}{np}\PY{o}{.}\PY{n}{log}\PY{p}{(}\PY{n}{ntp2}\PY{o}{.}\PY{n}{loc}\PY{p}{[}\PY{n}{prev\PYZus{}tag}\PY{p}{,} \PY{n}{next\PYZus{}tag}\PY{p}{]}\PY{p}{)} \PY{c+c1}{\PYZsh{} emission prop} \PY{n}{ep} \PY{o}{=} \PY{n}{token\PYZus{}emp}\PY{o}{.}\PY{n}{loc}\PY{p}{[}\PY{n}{next\PYZus{}tag}\PY{p}{]} \PY{n}{next\PYZus{}tag\PYZus{}p} \PY{o}{=} \PY{n}{tp} \PY{o}{+} \PY{n}{ep} \PY{o}{+} \PY{n}{prev\PYZus{}tag\PYZus{}p} \PY{n}{prev\PYZus{}table}\PY{o}{.}\PY{n}{append}\PY{p}{(}\PY{p}{(}\PY{n}{next\PYZus{}tag\PYZus{}p}\PY{p}{,} \PY{n}{next\PYZus{}tag}\PY{p}{,} \PY{n}{prev\PYZus{}tag}\PY{p}{)}\PY{p}{)} \PY{n}{next\PYZus{}table}\PY{o}{.}\PY{n}{append}\PY{p}{(}\PY{n+nb}{max}\PY{p}{(}\PY{n}{prev\PYZus{}table}\PY{p}{)}\PY{p}{)} \PY{n}{table}\PY{o}{.}\PY{n}{append}\PY{p}{(}\PY{n}{next\PYZus{}table}\PY{p}{)} \end{Verbatim} \begin{Verbatim}[commandchars=\\\{\}] {\color{incolor}In [{\color{incolor}217}]:} \PY{n}{pos\PYZus{}tags} \PY{o}{=} \PY{p}{[}\PY{p}{]} \PY{c+c1}{\PYZsh{} Start not from the last, but from the one before the last, because we cannot handle \PYZsq{}.\PYZsq{} correctly} \PY{n}{prev} \PY{o}{=} \PY{n+nb}{max}\PY{p}{(}\PY{n}{table}\PY{p}{[}\PY{o}{\PYZhy{}}\PY{l+m+mi}{1}\PY{p}{]}\PY{p}{)} \PY{k}{for} \PY{n}{current} \PY{o+ow}{in} \PY{n}{table}\PY{p}{[}\PY{o}{\PYZhy{}}\PY{l+m+mi}{2}\PY{p}{:}\PY{p}{:}\PY{o}{\PYZhy{}}\PY{l+m+mi}{1}\PY{p}{]}\PY{p}{:} \PY{n}{pos\PYZus{}tags}\PY{o}{.}\PY{n}{append}\PY{p}{(}\PY{n}{prev}\PY{p}{[}\PY{l+m+mi}{1}\PY{p}{]}\PY{p}{)} \PY{k}{for} \PY{n}{t} \PY{o+ow}{in} \PY{n}{current}\PY{p}{:} \PY{k}{if} \PY{n}{t}\PY{p}{[}\PY{l+m+mi}{1}\PY{p}{]} \PY{o}{==} \PY{n}{prev}\PY{p}{[}\PY{l+m+mi}{2}\PY{p}{]}\PY{p}{:} \PY{n}{prev} \PY{o}{=} \PY{n}{t} \PY{k}{break} \PY{n}{pos\PYZus{}tags}\PY{o}{.}\PY{n}{append}\PY{p}{(}\PY{n}{prev}\PY{p}{[}\PY{l+m+mi}{1}\PY{p}{]}\PY{p}{)} \end{Verbatim} \begin{Verbatim}[commandchars=\\\{\}] {\color{incolor}In [{\color{incolor}218}]:} \PY{k}{for} \PY{n}{w}\PY{p}{,} \PY{n}{tag} \PY{o+ow}{in} \PY{n+nb}{zip}\PY{p}{(}\PY{n}{sentence}\PY{p}{,} \PY{n}{pos\PYZus{}tags}\PY{p}{[}\PY{p}{:}\PY{p}{:}\PY{o}{\PYZhy{}}\PY{l+m+mi}{1}\PY{p}{]}\PY{p}{)}\PY{p}{:} \PY{n+nb}{print}\PY{p}{(}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+si}{\PYZpc{}s}\PY{l+s+s1}{|}\PY{l+s+si}{\PYZpc{}s}\PY{l+s+s1}{ }\PY{l+s+s1}{\PYZsq{}}\PY{o}{\PYZpc{}} \PY{p}{(}\PY{n}{w}\PY{p}{,} \PY{n}{tag}\PY{p}{)}\PY{p}{,} \PY{n}{end}\PY{o}{=}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{\PYZsq{}}\PY{p}{)} \end{Verbatim} \begin{Verbatim}[commandchars=\\\{\}] <S>|<S> habla|VMIP3S0 de|SPS00 trasplantes|NCMP000 con|SPS00 el|DA0MS0 enfermo|NCMS000 grave|AQ0CS0 .|Fp <E>|<E> \end{Verbatim} \begin{Verbatim}[commandchars=\\\{\}] {\color{incolor}In [{\color{incolor}219}]:} \PY{n}{relevant\PYZus{}tp} \PY{o}{=} \PY{n}{ntp}\PY{o}{.}\PY{n}{loc}\PY{p}{[}\PY{n}{pos\PYZus{}tags}\PY{p}{,} \PY{n}{pos\PYZus{}tags}\PY{p}{]} \PY{n}{relevant\PYZus{}tp} \end{Verbatim} \begin{Verbatim}[commandchars=\\\{\}] {\color{outcolor}Out[{\color{outcolor}219}]:} <E> Fp AQ0CS0 NCMS000 DA0MS0 SPS00 NCMP000 SPS00 VMIP3S0 <S> <E> 0.0000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.0 Fp 0.9375 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.0 AQ0CS0 0.0000 0.000000 0.000000 0.176471 0.000000 0.176471 0.000000 0.176471 0.000000 0.0 NCMS000 0.0000 0.054054 0.108108 0.000000 0.027027 0.378378 0.000000 0.378378 0.000000 0.0 DA0MS0 0.0000 0.000000 0.040000 0.600000 0.000000 0.040000 0.000000 0.040000 0.000000 0.0 SPS00 0.0000 0.000000 0.000000 0.044118 0.235294 0.000000 0.044118 0.000000 0.000000 0.0 NCMP000 0.0000 0.125000 0.000000 0.000000 0.000000 0.125000 0.000000 0.125000 0.000000 0.0 SPS00 0.0000 0.000000 0.000000 0.044118 0.235294 0.000000 0.044118 0.000000 0.000000 0.0 VMIP3S0 0.0000 0.000000 0.000000 0.037037 0.037037 0.259259 0.000000 0.259259 0.037037 0.0 <S> 0.0000 0.000000 0.000000 0.000000 0.000000 0.400000 0.000000 0.400000 0.066667 0.0 \end{Verbatim} \hypertarget{graph-of-transition-probabilitis}{% \section{Graph of transition probabilitis}\label{graph-of-transition-probabilitis}} Generate a graph containing the transition probabilities of all tags contained in the sentence \begin{Verbatim}[commandchars=\\\{\}] {\color{incolor}In [{\color{incolor}220}]:} \PY{n}{G} \PY{o}{=} \PY{n}{nx}\PY{o}{.}\PY{n}{DiGraph}\PY{p}{(}\PY{p}{)} \PY{p}{[}\PY{n}{G}\PY{o}{.}\PY{n}{add\PYZus{}node}\PY{p}{(}\PY{n}{node}\PY{p}{)} \PY{k}{for} \PY{n}{node} \PY{o+ow}{in} \PY{n}{relevant\PYZus{}tp}\PY{o}{.}\PY{n}{columns}\PY{p}{]} \PY{k}{for} \PY{n}{src} \PY{o+ow}{in} \PY{n}{relevant\PYZus{}tp}\PY{o}{.}\PY{n}{columns}\PY{p}{:} \PY{k}{for} \PY{n}{dest} \PY{o+ow}{in} \PY{n}{relevant\PYZus{}tp}\PY{o}{.}\PY{n}{columns}\PY{p}{:} \PY{n}{w} \PY{o}{=} \PY{n}{ntp}\PY{o}{.}\PY{n}{loc}\PY{p}{[}\PY{n}{src}\PY{p}{,} \PY{n}{dest}\PY{p}{]} \PY{k}{if} \PY{n}{w} \PY{o}{\PYZgt{}} \PY{l+m+mf}{0.0}\PY{p}{:} \PY{n}{G}\PY{o}{.}\PY{n}{add\PYZus{}edge}\PY{p}{(}\PY{n}{src}\PY{p}{,} \PY{n}{dest}\PY{p}{,} \PY{n}{label}\PY{o}{=}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+si}{\PYZpc{}1.2f}\PY{l+s+s1}{\PYZsq{}}\PY{o}{\PYZpc{}}\PY{k}{w}) \end{Verbatim} \begin{Verbatim}[commandchars=\\\{\}] {\color{incolor}In [{\color{incolor}221}]:} \PY{c+c1}{\PYZsh{} Write to disk and run dot \PYZhy{}Tpng transition\PYZus{}graph.dot \PYZgt{} transition\PYZus{}graph.png} \PY{n}{nx}\PY{o}{.}\PY{n}{nx\PYZus{}agraph}\PY{o}{.}\PY{n}{write\PYZus{}dot}\PY{p}{(}\PY{n}{G}\PY{p}{,} \PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{transition\PYZus{}graph.dot}\PY{l+s+s1}{\PYZsq{}}\PY{p}{)} \end{Verbatim} \begin{Verbatim}[commandchars=\\\{\}] {\color{incolor}In [{\color{incolor}227}]:} \PY{n}{graph} \PY{o}{=} \PY{n}{plt}\PY{o}{.}\PY{n}{imread}\PY{p}{(}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{transition\PYZus{}graph.png}\PY{l+s+s1}{\PYZsq{}}\PY{p}{)} \PY{n}{plt}\PY{o}{.}\PY{n}{figure}\PY{p}{(}\PY{n}{figsize}\PY{o}{=}\PY{p}{(}\PY{l+m+mi}{15}\PY{p}{,} \PY{l+m+mi}{15}\PY{p}{)}\PY{p}{)} \PY{n}{plt}\PY{o}{.}\PY{n}{imshow}\PY{p}{(}\PY{n}{graph}\PY{p}{)} \PY{n}{plt}\PY{o}{.}\PY{n}{show}\PY{p}{(}\PY{p}{)} \end{Verbatim} \begin{center} \adjustimage{max size={0.9\linewidth}{0.9\paperheight}}{output_22_0.png} \end{center} { \hspace*{\fill} \\} % Add a bibliography block to the postdoc \end{document}
\chapter{Background} \label{ch:background} % http://www.ccs.neu.edu/home/will/CPP/dangling.html has a good example of a dangling pointer error leading to double delete \section{Virtual memory} Virtual memory is an abstraction over the physical memory available to the hardware. It is an abstraction that is typically transparent to both the applications and developers, meaning that they do not have to be aware of it, while enjoying the significant benefits. This is enabled by the hardware and operating system kernel working together in the background. From a security and stability point of view, the biggest benefit that virtual memory provides is address space isolation: each process executes as if it was the only one running, with all of the memory visible to it belonging either to itself or the kernel. This means that a malicious or misbehaving application cannot directly access the memory of any other process, to either deliberately or due to a programming error expose secrets of the other application (such as passwords or private keys) or destabilize it by corrupting its memory. An additional security feature is the ability to specify permission flags on individual memory pages: they can be independently made readable, writeable, and executable. For instance, all memory containing application data can be marked as readable, writeable, but not executable, while the memory pages hosting the application code can be made readable, executable, but not writeable, limiting the capabilities of attackers. Furthermore, virtual memory allows the kernel to optimize physical memory usage by: \begin{itemize} \item Compressing or swapping out (writing to hard disk) rarely used memory pages (regions) to reduce memory usage \item De-duplicating identical memory pages, such as those resulting from commonly used static or shared libraries \item Lazily allocating memory pages requested by the application \end{itemize} Virtual memory works by creating an artificial (virtual) address space for each process, and then mapping the appropriate regions of it to the backing physical memory. A pointer will reference a location in virtual memory, and upon access, is resolved (typically by the hardware) into a physical memory address. The granularity of the mapping is referred to as a memory page, and is typically 4096 bytes (4 kilobytes) in size. (See Figure~\ref{fig:virtual_memory}.) \begin{figure} \centering \includegraphics[width=\textwidth]{diagrams/virtual_memory.png} \caption{Mapping two physical memory pages X and Y to virtual memory} \label{fig:virtual_memory} \end{figure} This mapping is encoded in a data structure called the \emph{page table}. This is built up and managed by the kernel: as the application allocates and frees memory, virtual memory mappings have be created and destroyed. The representation of the page table varies depending on the architecture, but on x86-64, it can be represented as a tree, with each node an array of 512 page table entries of 8 bytes each making up a 4096 byte page table page. The root of this tree is where all virtual memory address resolution begins, and it identifies the address space. The leaf nodes are the physical memory pages that contain the application's own data. The bits of the virtual memory address identify the page table entry to follow during address resolution. For each level of page tables, 9 bits are required to encode an index into the array of 512 entries. Each entry contains the physical memory address of the next page to traverse during the address resolution, as well as a series of bits that represent the different access permissions, such as writeable and executable. Finally, the least-significant 12 bits are used to address into the application's physical page (which is 4096 bytes) itself and so require no translation. (See Figure~\ref{fig:page_table_tree}.) On x86-64, there are currently 4 levels of page tables, using $4 \times 9 + 12 = 48$ out of the 64 available bits in the memory addresses, and limiting the size of the address space to $2^{48}$ bytes or 256 terabytes. (The size of addressable space per page table level, in reverse resolution order being: $512 \times 4$ kilobytes = 2 megabytes; $512 \times 2$ megabytes = 1 gigabyte; 512 gigabytes; 256 terabytes.) \begin{figure} \centering \includegraphics[width=\textwidth]{diagrams/page_table_tree.png} \caption{Translating a virtual memory address to physical using the page tables} \label{fig:page_table_tree} \end{figure} It is important to realize that it is possible to map a physical page into multiple virtual pages, as well as to have unmapped virtual pages. Attempting to access a virtual page (by dereferencing a pointer to it) that is not mapped -- i.e.\ not backed by a physical memory page -- will cause a \emph{page fault} and execution to trap inside the kernel. The kernel then can decide what to do -- for instance if it determines that the memory access was in error (an \emph{access violation}), it passes the fault on to the process which usually terminates it. On Linux this is done by raising the \texttt{SIGSEGV} signal (segmentation violation or segmentation fault) in the process, normally aborting its execution. Other types of access violation, such as attempting to write a non-writeable page -- a page on which writing was disallowed by setting the corresponding bit in its page table entry to 0 -- or attempting to execute a non-executable page -- a page which has its no-execute bit set, a new addition in the x86-64 architecture over x86-32 -- will also trigger a page fault in the kernel the same way. This mechanism also allows the kernel to perform memory optimizations. These are important, because (physical) memory is often a scarce resource. For example, a common scenario is that multiple running processes use the same shared library. The shared library is a single binary file on disk that is loaded into memory by multiple processes, meaning that naively the same data would be loaded into memory multiple times, taking up precious resources for no gain. The kernel can instead load the shared library into physical memory only once and then map this region into the virtual address space of each user application. Other de-duplication opportunities include static libraries that are commonly linked into applications (such as the C standard library), or the same binary executing in multiple processes. In addition to memory de-duplication, the kernel can also choose to compress or even swap out rarely used memory. In these cases, the kernel marks the relevant page table entries as invalid, causing the hardware to trigger a page fault in the kernel if they are accessed. Upon access, instead of sending a signal to the process, the kernel restores the data by decompressing it or reading it from disk, after which it will resume the process which can continue without even being aware of what happened. Modern kernels such as Linux include a large number of similar optimizations~\cite{linux-kernel-mm}. % Thanks to Dune, Dangless has direct access to the page tables, and manipulates them using custom functions (see \textit{include/dangless/virtmem.h} and \textit{src/virtmem.c}). Upon memory allocation, Dangless forwards the allocation call to the system allocator and then reserves a new virtual page, mapping it to the same physical address as the a virtual page returned by the system allocator. This is called virtual aliasing. During deallocation, besides forwarding the call to the system allocator, Dangless unmaps the virtual alias page and overwrites the page table entry with a custom value, enabling it to recognize a would-be access through a dangling pointer. \section{Related work} \label{sec:related-work} Memory errors are a well-understood problem and a significant amount of research has already been conducted in this field. Numerous solutions have been proposed, often using similar ideas and offering alternative approaches, optimizations, or other incremental improvements. However, in spite of all this effort, memory errors remain extremely common~\cite{memerrors-past-present-future}. SafeC~\cite{safec1994}, published in 1994, transforms programs at compile-time by turning pointers into fat pointers, attaching to them metadata such as the size of the referenced object, its storage class (local, global, or heap), as well as a capability that references an entry in the global capability store, which maintains a record of all active dynamic memory. Detecting memory errors becomes a matter of checking the fat pointer metadata. Unsurprisingly, this approach comes with a very steep performance cost, both in terms of execution speed as well as memory usage. Improvements were proposed later by H. Patil and C. Fischer in 1997~\cite{safec-improved1997}, as well as by W. Xu, D. C. DuVarney, and R. Sekar in 2004~\cite{safec-improved2004}. Rational Purify~\cite{hastings1991purify} is another one of the earliest comprehensive tools for detecting memory errors, originally published in 1991, and existing in various forms until today as a paid product. Purify works by instrumenting the object code in order to keep track of each memory allocation and check every access. It provides a widespread range of features, detecting uninitialized memory accesses, buffer overflows and underflows, as well as dangling pointer errors so long as the memory has not been reused. However, there do not appear to be any published results on its performance characteristics. Electric Fence~\cite{electric-fence} and Microsoft PageHeap~\cite{pageheap} (now existing as part of the Global Flags Editor on Windows) are similar tools developed before 2000. They work by placing each allocation on their own virtual memory pages that is marked as protected upon deallocation to catch temporal memory errors. They also provide bounds checking using extra virtual memory. As such, they are the earliest implementations of the same idea that powers Dangless, but they do so with a very heavy overhead in performance and memory usage, so they are advertised as debugging tools. Another tool that is ultimately only deemed useful as a development and debugging utility, but still sees widespread use today is Valgrind~\cite{valgrind2007}. It is a dynamic binary instrumentation framework designed to build heavy-weight (i.e.\ computationally expensive) tools, in particular focused on shadow values which allows tools to store arbitrary metadata for each register and memory location, enabling the development of tooling that would otherwise be impossible. Valgrind Memcheck~\cite{valgrind-memcheck-web} is the tool that implements extensive memory checking. However, it is only capable of detecting dangling pointer errors until the memory region is reused, although effort is made to delay this for as long as possible, Dhurjati et al.\ proposed a different approach in 2003~\cite{dhurjati2003memory} that limits the severity of temporal memory errors by restricting memory re-use to be type-safe. This means that objects of different types are never allocated in a location where they could ever possibly alias. While this does not prevent all dangling pointer errors, it does ensure that type confusion does not occur, making the problem easier to diagnose and harder to exploit by a malicious user. Cling~\cite{akritidis2010cling} builds on top of the same idea and is a memory allocator that similarly limits, but does not prevent, the threat surface posed by dangling pointer errors by restricting memory re-use to objects of the same type. It does so by noting down the caller function of each memory allocation, assigning a unique memory pool to each, under the assumption that one call site always performs allocations of the same type. In 2006 Dhurjati et al.~\cite{dhurjati2006efficiently}\ presented a paper building on the ideas of Electric Fence and PageHeap, claiming that their approach detects all dangling pointer errors efficiently enough for it to be practical to use in production. They combine the idea of virtual memory remapping (using system calls) with a modified version of LLVM's~\cite{llvm-web} compiler transformation called Automatic Pool Allocation that allows them to safely reclaim virtual memory in cases when they are able to prove that no references remain to the allocated region. This requires the target application's source code to be available and the build process to be significantly modified. Their approach also adds an 8 byte overhead to each allocation, similarly to Electric Fence, in order to keep track of the canonical pointer. 2012 saw the introduction of the LLVM AddressSanitizer~\cite{llvm-address-sanitizer2012}. This is a safety tool easily enabled from Clang or another LLVM frontend, aiming to make memory checking more easily available for users. It relies on code instrumentation, as well as shadow memory acting as allocation metadata, similarly to Valgrind. DangNull~\cite{dangnull2015}'s approach from 2015 is similar in the sense that they utilize the LLVM compiler infrastructure to instrument the application code, gathering information during runtime about allocations, deallocations, and storage of pointer values. The goal, ultimately, is to be able to keep track of all pointers that refer to a given object, such that when the object is deallocated, all pointers can be sanitized, preventing use-after-free bugs. Dangsan~\cite{dangsan2017} in 2017 improved on the idea of DangNull and provided a more efficient implementation. DangDone~\cite{dangdone2018} is a recent proposal from 2018 in which an extra layer of pointer indirection is used to guard allocations. When allocating an object, an additional object is also allocated, containing the only pointer to the object itself, while the user code receives a pointer to the intermediary object. All memory loads and stores then have to be instrumented, such that the intermediary pointer is loaded, checked, and then the actual referenced object is read or written. When deallocating, the object itself is deallocated as normal, while the intermediary object remains dereferenceable, though invalid. The authors claim a negligible performance impact, although it is worth noting that they made their measurements with all compiler optimizations disabled. Undangle~\cite{undangle2012} is a tool presented in 2012 by Microsoft Research that aims to detect any dangling pointers as soon as they are created, regardless of whether they are used or lead to errors. It is built on top of the TEMU dynamic analysis platform~\cite{bitblaze-temu2008}, which in turn is implemented on top of the QEMU open-source whole-system emulator~\cite{qemu-web}. First, the binary under test is executed inside the emulated analysis environment, producing an execution trace as well as an allocation log. Undangle then uses these as inputs to perform the dangling pointer detection, leveraging a pointer tracking module which is built upon a generic taint analysis module. Oscar~\cite{oscar2017}, put forward in 2017, is another iteration on the idea of Electric Fence and PageHeap. They similarly re-map virtual pages, by creating ``shadow pages'', and store an additional pointer to the canonical virtual page with each allocation. Improving on previous approaches, they present techniques for optimizing performance by decreasing the number of system calls needed. Dangless builds on top of the same ideas as Electric Fence, PageHeap, Dhurjati et al., and Oscar, but is able to improve on their performance by moving the process being protected into a virtualized environment, where the virtual memory page protections can be manipulated efficiently. \section{Unikernels and Rumprun} The idea of unikernels stems from the observation~\cite{unikernels-intro} that in many cloud deployment scenarios, a virtual machine is typically used to host only a single application, such as a web server or database server. These virtual machines all run a commodity operating system -- typically a Linux distribution, or less often, Windows -- that is built to support multiple users and many arbitrary applications running concurrently on various hardware. This adds up to a significant amount of effectively dead code in these scenarios. A tiny library operating system with only the necessary modules enabled and tied directly together with the application would result in a much more efficient image. Given the widespread use of cloud technologies and the prevalence of commodity cloud providers since 2013, unikernels and similar technologies became a topic of research and development, yielding solutions such as MirageOS, IncludeOS, Rump kernels, HaLVM, and OSv~\cite{unikernels-list}. Notably, similar research has also resulted in technologies such as Docker~\cite{docker-web}. One approach to building unikernels is basing them on applications developed for commodity operating systems, and then through a mix of manual and automated methods adapt them to be able to run with a unikernel runtime. This approach is taken by Rump kernels~\cite{rumpkernels-web}, which provides various drivers and operating system modules (based on NetBSD) as well as a near-complete POSIX system call interface, allowing many existing applications to be run without any modifications~\cite{rumpkernels-doc}. When the development of Dangless began, it was initially supporting both Rumpkernels and Dune. However, over time, maintaining both has become a major burden, and focus shifted to only supporting Dune. One of the reasons for this was entirely practical: development of Dangless on Rumpkernels was more difficult, due to the complete virtual machine isolation which is required to run them, making debugging and data collection (statistics, logging) more difficult. Furthermore, Rumpkernels would have also needed custom modifications (similarly to how Dune ended up requiring them), for instance in order to make it possible for Dangless to provide the symbols for \lstinline!malloc()! and co. while Rumpkernels also define the same strong symbols. Regardless, I still believe that unikernels are a promising field, because it is focused on providing environments for efficiently hosting long-running, publicly exposed services such as web servers, which are particularly relevant for security research, and by extension for Dangless itself. \section{Dune: light-weight process virtualization} \label{sec:bg-dune} Dune~\cite{dune-website} is a technology developed to enable the development of Linux applications that can run on an unmodified Linux kernel while having the ability to directly and safely (in isolation from the rest of the system) access hardware features normally reserved for the kernel (ring 0) code~\cite{dune-paper}. Importantly, while getting all the benefits of having direct access to privileged hardware features, the application still has access to the Linux host operating system's interface (system calls) and features. This means that the same process that can, for instance, directly manipulate its own interrupt descriptor table, can also call a normal \lstinline!fopen()! function (or \lstinline!open()! Linux system call) and it will behave as expected: the system call will pass through to the host kernel. This is achieved using hardware-assisted virtualization (Intel VT-x) on the process level, rather than on the more common machine level. Dune consists of a kernel module \texttt{dune.ko} for x86-64 Linux that initializes the virtual environment and mediates between the Dune-mode process and the host kernel, as well as a user-level library called \texttt{libdune} for setting up and managing the virtualized (guest) hardware. The two components communicate via the \lstinline!ioctl()! system call on the \texttt{/dev/dune} special device that is exposed by the kernel module. Finally, \path{libdune/dune.h} exposes a number of functions to help the application manage the now-accessible hardware features. An application wishing to use Dune has to statically link to \path{libdune.a}, and call \lstinline!dune_init()! and \lstinline!dune_enter()! to enter Dune mode. For this to succeed, the Dune kernel mode has to be already loaded. That done, the application keeps running as before: file descriptors remain valid, system calls continue to work, and so on, except privileged hardware features also become available. This opens up drastically more efficient methods of implementing some applications, such as those utilizing garbage collection, process migration, and sandboxing untrusted code. It also enables Dangless to work efficiently. \subsection{Patching Dune} Dangless was built using ix-project's fork of Dune~\cite{dune-github-ix}, because when the Dangless project started that was more maintained and supported more recent kernel versions. However, since then, work appears to have resumed on the original Dune repository~\cite{dune-github-original}, and they now claim to be supporting Linux kernel versions 4.x. I have patched Dune with a couple of modifications to allow Dangless to do its work. These are available in the \path{vendor} directory in the Dangless source code. \path{dune-ix-guestppages.patch}: this maps the guest system's pagetable pages into its own virtual memory, allowing Dangless to modify them. The code for this already existed in the original implementation of Dune, but was removed at some point from the ix-project's fork. \path{dune-ix-nosigterm.patch}: for unclear reasons, upon exiting, Dune was raising the \lstinline!SIGTERM! signal, causing the Dune process to appear to have crashed even when it exited normally. This patch disables this behaviour, without appearing to affect anything else. \path{dune-ix-vmcallhooks.patch}: this is a significant patch that allows a pre- and post-hook to be registered for \lstinline!vmcall!-s. That is, any time a system call is not handled inside Dune, and is about to be forwarded to the host kernel, the pre-hook, if set, is invoked with the system call number, arguments, and return address, allowing the hook to inspect and modify them. Similarly, once the \lstinline!vmcall! returns, but before the normal code execution resumes, the post-hook is invoked, with the system call result passed to it as argument. This is critical for Dangless, and is explained in detail by Section~\ref{sec:vmcall-pointer-rewriting}. Finally, Dangless contains a work-around for an issue in Dune which appears with allocation-heavy code. \texttt{glibc}'s default \lstinline!malloc()! implementation relies on the \lstinline!brk()! system call to perform small memory allocations (in my tests, up to 9000 bytes). After a sufficient number of \lstinline!brk()! calls, the resulting address crosses the 4 GB boundary, i.e.\ the memory address \texttt{0x100000000}. However, this area does not appear to be mapped by Dune in the embedded page table, causing an EPT violation error on access. In the Dangless source code, \path{testapps/memstress} can be used to trigger this bug: \begin{verbatim} $ cd build/testapps/memstress $ ./memstress 1500000 9000 \end{verbatim} To work around this, Dangless registers a post-\lstinline!vmcall! hook, and if it detects a \lstinline!brk()! system call with a parameter above the 4 GB mark, it overwrites the system call's return code to make it appear to have failed. \texttt{glibc}'s memory allocator will then fall back to using \lstinline!mmap()! even for these smaller allocations, which will continue to work. \subsection{Memory layout} Dune offers two memory layouts, specified when calling \lstinline!dune_init()!: precise and full mappings. With precise mappings, Dune will consult \path{/proc/self/maps} for the memory regions of the so-far ordinary Linux process and map each region found there into the guest environment. With the version of Dune I was using for development, this did not appear to work correctly, and so I used full mappings for Dangless. In full mappings, Dune creates the following mappings in the guest virtual memory: \begin{itemize} \item Identity-mapping for the first 4 GB of memory: this is where the executable code and data lives, so this is also where the default \lstinline!malloc()! implementation places small memory allocations (allocated via \lstinline!brk()!) \item The stack memory, max 1 GB \item The mmap memory region, max 63 GB \item The static \texttt{VDSO} and \texttt{VVAR} regions \item Any mappings needed for the executable and libraries (code and data) \end{itemize} Furthermore, the Dune kernel module creates the embedded page table (EPT), the part of the Intel VT-x virtualization technology that is used for translating host virtual addresses (HVA) to guest physical addresses (GPA) and vica versa. The EPT is set up and is kept in sync with the process memory automatically, meaning that mappings are created on-demand on EPT faults, within the limits of the layout defined by Dune and described above. Dangless makes extensive use of the knowledge of the guest memory layout, for instance for translating physical addresses (e.g.\ of pagetable pages) to virtual addresses.