\chapter{Getting Started with QuTiP}

\par This chapter discusses the basics of QuTiP and how it can be used in quantum information work.

\section{QuTiP Basics}
QuTiP is a large library. Understanding all of it will need much more background knowledge than the scope of this project. Here we only explain some basics to help the reader get started. The more curious reader can consult the QuTiP documentation. \cite{qutipdoc}
\par First of all we need to understand the basic data structure which represents quantum states, operators and other matrices in QuTiP. This is called the quantum object class (\texttt{Qobj}) in QuTiP.

\subsection{The Quantum Object Class}
The quantum object, or \texttt{Qobj} in short, is the basic data structure that all of QuTiP's functions will work on. It is a matrix with some context information added about what exactly it represents in terms of quantum mechanics. In addition to the data about what it represents, it also has various built-in methods to perform calculations on it.
\par To get started, let us create a simple blank \texttt{Qobj}. The qutip module will need to be imported first. Most of our code will also use functions from NumPy so we import that too.
\begin{verbatim}
In [1]: from qutip import *
In [2]: import numpy as np
\end{verbatim}
This imports all functions from the qutip module and imports numpy with a shorter name np for convenience. Now we are ready to create a Qobj instance.
\begin{verbatim}
In [3]: Qobj()
Out[3]:
Quantum object: dims = [[1], [1]], shape = [1, 1], type = oper, isherm = True
Qobj data =
[[ 0.]]
\end{verbatim}
We see that calling Qobj() without any arguments returns a 1x1 matrix with a zero entry. There is also some additional information printed out: the dimensions of the object, its type which is an operator and whether or not the matrix is Hermitian. There is also additional information stored in the Qobj which is not displayed here or in a simple print statement.
\par The Qobj can also take user input, for example, for the entries of the matrix.
\begin{verbatim}
In [4]: Qobj([[1],[0]])
Out[4]:
Quantum object: dims = [[2], [1]], shape = [2, 1], type = ket
Qobj data =
[[ 1.]
 [ 0.]]
In [5]: Qobj([[1,0],[0,0]])
Out[5]:
Quantum object: dims = [[2], [2]], shape = [2, 2], type = oper, isherm = True
Qobj data =
[[ 1.  0.]
 [ 0.  0.]]
\end{verbatim}
In the above example, we used a list of lists as input. We could also have used a numpy array or matrix. For more information on how to initialize a Qobj instance, the reader can use the built-in help: \texttt{help(Qobj)}

\subsection{Basic Operations on Quantum Objects}
Let us try to create this state in QuTiP.
\begin{align*}
\ket{\psi_1} = \frac{2}{\sqrt{5}} \ket{0} + \frac{1}{\sqrt{5}} \ket{1}
\end{align*}

\begin{verbatim}
In [1]: from qutip import *
In [2]: import numpy as np
In [3]: up = basis(2,0)
In [4]: dn = basis(2,1)
In [5]: print(up)
Quantum object: dims = [[2], [1]], shape = [2, 1], type = ket
Qobj data =
[[ 1.]
 [ 0.]]
In [6]: psi1 = ( 2/np.sqrt(5) * up ) + ( 1/np.sqrt(5) * dn )
In [7]: print(psi1)
Quantum object: dims = [[2], [1]], shape = [2, 1], type = ket
Qobj data =
[[ 0.89442719]
 [ 0.4472136 ]]
\end{verbatim}
The function \texttt{basis(2,0)} creates a state ket vector of length 2 with its zeroth index (i.e. first entry) as 1 and the rest of the entries zero. Similarly \texttt{basis(2,1)} makes the second entry 1 and the rest zero.
\par To calculate the density matrix for $\ket{\psi_1}$, we can multiply it with its conjugate transpose ( \texttt{psi1.dag()} ) or simply use the function \texttt{ket2dm} provided by QuTiP which takes a ket vector and returns its density matrix.
\begin{verbatim}
In [8]: psi1 * psi1.dag()
Out[8]:
Quantum object: dims = [[2], [2]], shape = [2, 2], type = oper, isherm = True
Qobj data =
[[ 0.8  0.4]
 [ 0.4  0.2]]

In [9]: ket2dm(psi1)
Out[9]:
Quantum object: dims = [[2], [2]], shape = [2, 2], type = oper, isherm = True
Qobj data =
[[ 0.8  0.4]
 [ 0.4  0.2]]
\end{verbatim}
For tensor products, QuTiP has a built-in function \texttt{tensor}.
\begin{verbatim}
In [10]: tensor(up,dn)
Out[10]:
Quantum object: dims = [[2, 2], [1, 1]], shape = [4, 1], type = ket
Qobj data =
[[ 0.]
 [ 1.]
 [ 0.]
 [ 0.]]
\end{verbatim}
Notice how the dimensions value changes because now we are representing a composite object in an extended Hilbert space.
\par Let us now create a maximally entangled state
\begin{align*}
\ket{\psi_{AB}} = \frac{1}{\sqrt{2}} \left( \ket{0}_A \ket{0}_B + \ket{1}_A \ket{1}_B \right)
\end{align*}

\begin{verbatim}
In [11]: psi_ab = 1/np.sqrt(2) * ( tensor(up,up) + tensor(dn,dn) )

In [12]: print(psi_ab)
Quantum object: dims = [[2, 2], [1, 1]], shape = [4, 1], type = ket
Qobj data =
[[ 0.70710678]
 [ 0.        ]
 [ 0.        ]
 [ 0.70710678]]
\end{verbatim}
\par QuTiP also has a shortcut to create maximally entangled states (also known as Bell states) via the \texttt{bell\_state} function.
\begin{verbatim}
In [13]: bell_state('00')
Out[13]:
Quantum object: dims = [[2, 2], [1, 1]], shape = [4, 1], type = ket
Qobj data =
[[ 0.70710678]
 [ 0.        ]
 [ 0.        ]
 [ 0.70710678]]
\end{verbatim}
The input argument to \texttt{bell\_state} is one of '00', '01', '10' or '11' representing the four Bell states.
\par Let us now calculate some properties of \texttt{psi\_ab}.
\begin{verbatim}
In [16]: entropy_vn(psi_ab)
Out[16]: 2.220446049250313e-16

In [17]: concurrence(psi_ab)
Out[17]: 0.99999999999999978
\end{verbatim}
We can see that its von Neumann entropy is 0 within computational error range and concurrence is 1, as expected.
\par To take the trace of the density matrix for $\ket{\psi_{AB}}$, we use the \texttt{tr()} method for the \texttt{Qobj}. We can see that the trace values for the density matrix and the density matrix squared are 1, indicating a pure state as expected.
\begin{verbatim}
In [20]: ket2dm(psi_ab).tr()
Out[20]: 0.9999999999999998

In [21]: (ket2dm(psi_ab)**2).tr()
Out[21]: 0.9999999999999996
\end{verbatim}
\par QuTiP also has a partial trace operation which shall be useful in our calculations.
\begin{verbatim}
In [22]: ptrace(psi_ab,0)
Out[22]:
Quantum object: dims = [[2], [2]], shape = [2, 2], type = oper, isherm = True
Qobj data =
[[ 0.5  0. ]
 [ 0.   0.5]]
\end{verbatim}
The \texttt{ptrace} function accepts state vectors as well as density matrices as input. The second argument is which subsystems to keep in the partial trace. In this case, 0 is for A and 1 is for B. We have told it to calculate the density matrix for subsystem A.
\par Let us now calculate the probability of projecting atom A on ground state ($\ket{0}$ or $\ket{\uparrow}$) and B on excited state ($\ket{1}$ or $\ket{\downarrow}$). First we shall need to calculate the projector $\ket{0} \bra{0} \otimes \ket{1} \bra{1}$. Then we apply it to the density matrix and take the trace to find the probability of the atoms collapsing to that state.
\begin{verbatim}
In [24]: a0 = up * up.dag()
In [25]: b1 = dn * dn.dag()
In [26]: prj_a0b1 = tensor(a0,b1)
In [27]: print(prj_a0b1)
Quantum object: dims = [[2, 2], [2, 2]], shape = [4, 4], type = oper,
isherm = True
Qobj data =
[[ 0.  0.  0.  0.]
 [ 0.  1.  0.  0.]
 [ 0.  0.  0.  0.]
 [ 0.  0.  0.  0.]]
In [28]: print(ket2dm(psi_ab))
Quantum object: dims = [[2, 2], [2, 2]], shape = [4, 4], type = oper,
isherm = True
Qobj data =
[[ 0.5  0.   0.   0.5]
 [ 0.   0.   0.   0. ]
 [ 0.   0.   0.   0. ]
 [ 0.5  0.   0.   0.5]]
In [29]: res_matrix = prj_a0b1 * ket2dm(psi_ab)
In [30]: print(res_matrix)
Quantum object: dims = [[2, 2], [2, 2]], shape = [4, 4], type = oper,
isherm = True
Qobj data =
[[ 0.  0.  0.  0.]
 [ 0.  0.  0.  0.]
 [ 0.  0.  0.  0.]
 [ 0.  0.  0.  0.]]
In [31]: res_matrix.tr()
Out[31]: 0.0
\end{verbatim}
\par The expectation value is \textit{zero} which means that if we measure the states of the atoms, there is no chance that we will find them anticorrelated such that the atom A is in ground state and the atom B is in excited state. This is in agreement with what we would expect by simply looking at the equation of the entangled state where the coefficient for $\ket{0}_A \ket{1}_B$ is zero.
\par QuTiP provides an easier way to calculate the expectation values of operators on states via the \texttt{expect} function.
\begin{verbatim}
In [36]: expect(prj_a0b1,psi_ab)
Out[36]: 0.0
In [37]: expect(prj_a0b1,ket2dm(psi_ab))
Out[37]: 0.0
\end{verbatim}
The \texttt{expect} function takes an operator and one or more states. For states, we can pass it the ket vector or the density matrix.

\section{Quantum Information Computations with QuTiP}
Now that we have demonstrated the basics of QuTiP, we move on to some slightly advanced calculations involving quantum information. All of the calculations and simulations appearing next have been based on Plenio's review paper \cite{pleniophysforget}.
\subsection{No Cloning of Quantum Bits}
The no-cloning theorem in quantum information theory states that quantum bits cannot be cloned \cite{nielsenchuang}. In this part, with the help of a practical example, we make an argument for its validity. We start with a thought experiment where Alice sends Bob a message encoded in quantum states and Bob has to extract that information. We take a look at what would happen if Bob could clone those quantum bits that he receives.
\par Initially Alice encodes symbols 0 and 1, occurring with equal probabilities, in the non-orthogonal states $\ket{\psi_0}$ and $\ket{\psi_1}$.
\begin{align*}
0 \longmapsto \ket{\psi_0} &= \ket{\uparrow} \\
1 \longmapsto \ket{\psi_1} &= \frac{1}{\sqrt{2}} \ket{\uparrow} + \frac{1}{\sqrt{2}} \ket{\downarrow}
\end{align*}

\begin{verbatim}
In [1]: from qutip import *
In [2]: import numpy as np
In [3]: up = basis(2,0)
In [4]: dn = basis(2,1)
In [5]: psi0 = up
In [6]: psi1 = 1/np.sqrt(2) * ( up + dn )
\end{verbatim}

The upper bound to information transmitted per letter is given by $S(\rho)$ where $\rho$ represents the incomplete knowledge that we have of the state of each carrier.
\begin{align*}
\rho = \frac{1}{2} \ket{\psi_0} \bra{\psi_0} + \frac{1}{2} \ket{\psi_1} \bra{\psi_1}
\end{align*}

\begin{verbatim}
In [7]: rho = 0.5 * ( ket2dm(psi0) + ket2dm(psi1) )
In [8]: entropy_vn(rho,2)
Out[8]: 0.6008760366928562
\end{verbatim}
The second argument for \texttt{entropy\_vn} is the base of log used when calculating the von Neumann entropy, which is 2 here since there are two possible states. Notice that the von Neumann entropy is less than 1 bit due to non-orthogonality of the states.
\par Now Alice transmits her message, encoded in these symbols, to Bob who knows the encoding procedure for the symbols but does not know the exact message. The maximum information that Bob can recover is the information that Alice has encoded: i.e. $S(\rho) = 0.6008760366928562$
\par Now let us assume that Bob can somehow clone an arbitrary unknown quantum state. If that happens then upon receiving $\ket{\psi_0}$ or $\ket{\psi_1}$ he can create a copy. In such a situation he will end up with two copies of the 0 state $\ket{\psi_0} \ket{\psi_0}$ and two copies of the 1 state $\ket{\psi_1} \ket{\psi_1}$ which will both occur with equal probability 0.5. The density operator for this situation will be
\begin{align*}
\rho_{2copies} = \frac{1}{2} \ket{\psi_0} \ket{\psi_0} \bra{\psi_0} \bra{\psi_0} + \frac{1}{2} \ket{\psi_1} \ket{\psi_1} \bra{\psi_1} \bra{\psi_1}
\end{align*}
Let us now calculate how much information Bob can recover from this state after he has cloned the qubits. That will be the von Neumann entropy of this new state, $S(\rho_{2copies})$.
\begin{verbatim}
In [10]: psi0psi0 = tensor(psi0,psi0)
In [11]: psi1psi1 = tensor(psi1,psi1)
In [12]: rho_2cp = 0.5 * ( ket2dm(psi0psi0) + ket2dm(psi1psi1) )
In [13]: entropy_vn(rho_2cp,2)
Out[13]: 0.8112781244591345
\end{verbatim}
We see that
\begin{align*}
0.8112781244591345 &> 0.6008760366928562 \\
S(\rho_{2copies}) &> S(\rho)
\end{align*}
The information content of the state has increased, which should not be possible. If Bob can create infinite copies then he will eventually perfectly distinguish between two non-orthogonal states and will be able to extract 1 bit of information per symbol received. However this is not possible because we cannot extract more information than was originally encoded. \cite{pleniophysforget}

\subsection{Classical vs Quantum Correlations}
Let us start by considering a classically correlated state. Consider an apparatus that generates two beams of light in the mixed state.
\begin{align}
\hat{\rho}_{AB} = \frac{1}{2} \ket{HH} \bra{HH} + \frac{1}{2} \ket{VV} \bra{VV}
\end{align}
This equation tells us of a state where we either get the both beams horizontally polarized or both vertically polarized. We donot have complete knowledge of how the system was prepared, perhaps due to random fluctuations in the apparatus.
\\ We represent the state vectors $\ket{H}$ and $\ket{V}$ by these orthogonal vectors
\begin{align*}
\ket{H} \rightarrow \begin{pmatrix} 1\\0 \end{pmatrix} ; \ket{V} \rightarrow \begin{pmatrix} 0\\1 \end{pmatrix}
\end{align*}
If we place a polarizer in the beams' path then we will find that half the times both beams are horizontally polarized and half the times both are vertically polarized. Let us represent this state in QuTiP.
\begin{verbatim}
In [1]: from qutip import *
In [2]: import numpy as np
In [3]: h = basis(2,0)
In [4]: v = basis(2,1)
In [5]: hh = tensor(h,h)
In [6]: vv = tensor(v,v)
In [7]: rho_ab = 0.5*( ket2dm(hh) + ket2dm(vv) )   # Mixed state
In [8]: print(rho_ab)
Quantum object: dims = [[2, 2], [2, 2]], shape = [4, 4], type = oper,
isherm = True
Qobj data =
[[ 0.5  0.   0.   0. ]
 [ 0.   0.   0.   0. ]
 [ 0.   0.   0.   0. ]
 [ 0.   0.   0.   0.5]]
\end{verbatim}
\par Now let us compare it to a maximally entangled state where the correlations are purely quantum.
\begin{align*}
\ket{\psi_{AB}} &= \frac{1}{\sqrt{2}} \left( \ket{HH} + \ket{VV} \right) \\
\hat{\sigma}_{AB} &= \ket{\psi_{AB}} \bra{\psi_{AB}}
\end{align*}
Putting into code:
\begin{verbatim}
In [9]: psi_ab = bell_state('00')
In [10]: sgm_ab = ket2dm(psi_ab)
In [11]: print(sgm_ab)
Quantum object: dims = [[2, 2], [2, 2]], shape = [4, 4], type = oper, isherm = True
Qobj data =
[[ 0.5  0.   0.   0.5]
 [ 0.   0.   0.   0. ]
 [ 0.   0.   0.   0. ]
 [ 0.5  0.   0.   0.5]]
\end{verbatim}
\par We can clearly see that the density matrices for both are indeed different. But the question is how to distinguish between them in the lab. One such way is to rotate the basis (a local unitary transform). Entanglement of a system should not change under rotation of basis. Let us see if that makes a difference for our measurement outcomes.
\par We obtain the new basis vectors by rotating the polarizer by $45\deg$, which gives us the new basis vectors:
\begin{align*}
\ket{X} &= \frac{1}{\sqrt{2}} \left( \ket{V} + \ket{H} \right) \\
\ket{Y} &= \frac{1}{\sqrt{2}} \left( \ket{V} - \ket{H} \right)
\end{align*}

\begin{verbatim}
In [12]: X = 1/np.sqrt(2) * ( v + h )
In [13]: Y = 1/np.sqrt(2) * ( v - h )
\end{verbatim}
\par Let us now see if there is any probability of finding the beams in anti-correlated states: i.e. one in $\ket{X}$ and the other in $\ket{Y}$ direction. For that we need to construct the operator
\begin{align*}
\ket{X} \bra{X} \otimes \ket{Y} \bra{Y}
\end{align*}
\begin{verbatim}
In [14]: anticorr = tensor( ket2dm(X), ket2dm(Y) )
\end{verbatim}
\par Now let us see what probabilities we get for both of $\hat{\rho}_{AB}$ and $\hat{\sigma}_{AB}$.
\begin{verbatim}
In [15]: expect(anticorr,rho_ab)
Out[15]: 0.2499999999999999

In [16]: expect(anticorr,sgm_ab)
Out[16]: 0.0
\end{verbatim}
We can clearly see that quantum correlations donot change by a change of basis (a local unitary transformation) and there is zero probability for the maximally entangled state to come out anti-correlated after the transformation. On the other hand, for classically correlated states, there is a non-zero probability for the beams to come out in anti-correlated states.

\subsection{Creating an Entangled State}
We have discussed entanglement in quite some detail but how exactly do we prepare an entangled state? Suppose Alice and Bob hold two light beams. What will they have to do to entangle the photons?
\par The net entanglement in a system cannot be increased by local operations and classical communication on their own individual beams. To get them entangled, they will have to bring the beams together and let them interact.
\par Let us assume that Alice and Bob initially hold two separate non-interacting beams each polarized at an angle of $\pi/4$. The joint state of both their subsystems will be
\begin{align*}
\ket{\psi_{AB}}(0) &= \left( \frac{1}{\sqrt{2}} \ket{H}_A + \frac{1}{\sqrt{2}} \ket{V}_A \right) \otimes \left( \frac{1}{\sqrt{2}} \ket{H}_B + \frac{1}{\sqrt{2}} \ket{V}_B \right) \\
\end{align*}
Putting this into code:
\begin{verbatim}
In [1]: from qutip import *
In [2]: import numpy as np
In [3]: h = basis(2,0)
In [4]: v = basis(2,1)
In [5]: psi_a = 1/np.sqrt(2) * ( h + v )
In [6]: psi_b = 1/np.sqrt(2) * ( h + v )
In [7]: psi_ab_t0 = tensor(psi_a,psi_b)
In [8]: print(psi_ab_t0)
Quantum object: dims = [[2, 2], [1, 1]], shape = [4, 1], type = ket
Qobj data =
[[ 0.5]
 [ 0.5]
 [ 0.5]
 [ 0.5]]
\end{verbatim}
Let us confirm that this state is indeed disentangled using QuTiP's \texttt{concurrence} function.
\begin{verbatim}
In [9]: cncr = concurrence(psi_ab_t0)
In [10]: print(cncr)
Out[10]: 0
\end{verbatim}
\par The two beams in the initial state $\ket{\psi_{AB}}(0)$ are brought together and they start interacting. The time evolution of the state is determined by a joint Hamiltonian of the system which is represented by a 4x4 matrix because it will operate in the enlarged Hilbert space.
\par A suitable Hamiltonian for this pupose is
\begin{align*}
\hat{H} = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & -1 \\ \end{pmatrix}
\end{align*}
Putting it into code:
\begin{verbatim}
In [10]: hmlt = Qobj([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,-1]])
In [11]: hmlt.dims = [[2, 2], [2, 2]]
\end{verbatim}
Notice that this Hamiltonian is a composite object operating on a state of dimensions \texttt{[[2, 2], [2, 2]]}, which is why we give it the same dimensions so that it can operate on the state in the program.
\\The eigenstates of this Hamiltonian are $\ket{HH}$, $\ket{HV}$, $\ket{VH}$ and $\ket{VV}$ with corresponding eigenvalues 1, 1, 1 and -1.
\par The time evolution of the state $\ket{\psi_{AB}}(0)$ will be determined by solving the Schrodinger equation with this particular Hamiltonian.
\begin{align*}
i \hbar \frac{\delta \psi_{AB}(t)}{\delta t} = \hat{H} \psi_{AB}(t)
\end{align*}
Since the Hamiltonian is already diagonal, the solution of this equation can be written in vector form as
\begin{align*}
\psi_{AB}(t) = \exp \left( \frac{-i}{\hbar} \hat{H} t \right) \psi_{AB}(0)
\end{align*}
Now we need to find out how much time it will take before the state gets completely entangled. We start with time 0 and calculate the the concurrence of the resultant state at small intervals until it becomes 1 within the limit of computational error.
\begin{verbatim}
In [11]: t = 0
In [12]: dt = 0.01
In [13]: while np.round(cncr,6)!=1:
   ....:         t = t + dt
   ....:         hmltpr = (-1j*t) * hmlt
   ....:         hmlt_tf = hmltpr.expm()
   ....:         psi_ab_tf = hmlt_tf * psi_ab_t0
   ....:         cncr = concurrence(psi_ab_tf)
   ....:
In [14]: print("Final state psi_ab_tf =\n",psi_ab_tf)
Final state psi_ab_tf =
 Quantum object: dims = [[2, 2], [1, 1]], shape = [4, 1], type = ket
Qobj data =
[[ 0.00039816-0.49999984j]
 [ 0.00039816-0.49999984j]
 [ 0.00039816-0.49999984j]
 [ 0.00039816+0.49999984j]]

In [15]: print("time = ",t)
time = 1.5700000000000012
In [16]: print("concurrence = ", cncr)
concurrence = 0.99999967523
\end{verbatim}
The condition \texttt{np.round(cncr,6)!=1} rounds the value of concurrence and then checks if it is still not unity. The loop runs as long as the value is not 1. We have ignored the factor of $\hbar$ from the statement \texttt{(-1j*t)*hmlt} to make comparisons easier and prevent rounding errors due to the extremely small value of the constant. We can put it back at the end.
\par We see that the time taken to get to a maximally entangled state with $concurrence = 1$ takes approximately the time $t = \pi\hbar/2$. The reader can confirm by comparing the value to
\begin{verbatim}
In [17]: np.pi/2
Out[17]: 1.5707963267948966
\end{verbatim}
\par The final state we get is
\begin{align*}
\ket{\psi}_{AB} = \frac{-i}{2} \begin{pmatrix} 1\\1\\1\\-1 \end{pmatrix}
\end{align*}
\par The concurrence measure does tell us in a very reliable way that the state is not separable. But just for the sake of completeness, let us see if we can factorize this vector like a separable state (see section 2.4). We can write a simple equation solver using SciPy's \texttt{fsolve} to determine that.
\begin{verbatim}
import numpy as np
from scipy.optimize import fsolve

def solve_coefficients(coeffprod):
    """ Simple solver to separate a,b,c,d from products ac,ad,bc,bd

    Parameters
    ----------
    coeffprod : list
                [ac,ad,bc,bd] of which to separate a, b, c and d.

    -------
    z :       list
            The solutions [a,b,c,d]

    """
    ac,ad,bc,bd = coeffprod
    def f(x):
        a,b,c,d = x
        r = np.zeros(4)
        r[0] = a*c - ac
        r[1] = a*d - ad
        r[2] = b*c - bc
        r[3] = b*d - bd
        return r
    z = fsolve(f,[1,1,1,1])
    return z
\end{verbatim}
Let us give it the values $ac$, $ad$, $bc$ and $bd$ as input and let it try to find a solution for $a$, $b$, $c$ and $d$.
\begin{verbatim}
In [18]: coefprd = [1,1,1,-1]
In [19]: solve_coefficients(coefprd)
/usr/lib64/python3.4/site-packages/scipy/optimize/minpack.py:237:
RuntimeWarning: The iteration is not making good progress, as measured by the
  improvement from the last ten iterations.
  warnings.warn(msg, RuntimeWarning)
Out[19]: array([ 0.49960048,  1.18684841,  1.01693825, -0.41442035])
\end{verbatim}
\texttt{fsolve} raises an error that it cannot find a solution, which means that the state cannot be factorized into separate states - as expected. It should be noted, however, that this solver is not a very reliable and general indicator of separability. We shall discuss some reliable indicators in the next section.\\

\par Now that we have learnt to do some computations on quantum states using QuTiP, we proceed to the topic of extending it with quantum information functions.


\input{../header.tex}
\title{\vspace{-2cm}INF3490/INF4490 Exercise Solutions - Particle Swarms \& Cartesian Genetic Programming}
\author{Eivind Samuelsen\input{../author_footnote.tex}}
\date{}

% Removing paragraph indents is sometimes useful:
\setlength\parindent{0pt}
% ==============================================================================

% ================================= DOCUMENT ===================================
\begin{document}
    \renewcommand\marginsymbol[1][0pt]{%
  \tabto*{0cm}\makebox[-1cm][c]{$\mathbb{P}$}\tabto*{\TabPrevPos}}

\maketitle
\input{../intro.tex}

\section{Particle Swarm Optimizations}
The particle swarm velocity update formula is
\begin{equation}
    v_i^{(t+1)} \leftarrow \alpha v_i ^{(t)} + U(0,\beta)(p_i-x_i^{(t)}) + U(0,\beta)(p_g - x_i^{(t)})
\end{equation}
If we replaced the random terms related to personal and global best with a term proportional to the local objective function gradient, like this:
\begin{equation}
    v_i^{(t+1)} \leftarrow \alpha v_i ^{(t)} + \gamma \nabla f(x_i^{(t)})
\end{equation}
How would the particles behave? How does this compare to gradient ascent?\\

\textit{Answer:}

The only thing separating it from doing a bunch of gradient ascent runs is the term \(av_i^{(t)}\), that transfers a fraction of the displacement in the latest iteration, giving the particles a sort of momentum.
The particles would behave as balls that roll upwards instead of downwards.

\section{Cartesian Genetic Programming}
\begin{figure}[H]
\begin{center}
\includegraphics[width=0.9\textwidth]{cartesian.png}
\end{center}
\end{figure}
Using the setup above, construct circuits from the Cartesian genetic programming genotypes below:
\begin{itemize}
    \item 231 110 323 121 165 046 154 176 11 5 8 9
    \item 003 332 123 010 167 075 345 365 9 10 11 4
\end{itemize}

It isn't really necessary to know what the function numbers mean in order to draw the diagram.

The functions could be anything from simple binary operators (AND, OR, XOR, etc.) to real-valued arithmetic operators, to signal processing operations and so on.

\begin{figure}[H]
\begin{center}
\includegraphics[width=0.6\textwidth]{cgp_sol.png}
\end{center}
\end{figure}

\input{../contact.tex}
\end{document}
% ==============================================================================


\section{The geometric principle of physics laws}
\label{sec:geometric-principle-physics-laws}
%
\epigraph{Ubi materia, ibi geometria.}{Johannes Kepler}

Herein, the \lingo{geometric principle of physics laws} will permeate our way of doing physics:~\cite[chap. 1, p. iii]{thorne2013}
%
\begin{axiom}[Geometric principle]\label{axm:geometric-principle-physics-laws}
  The laws of physics must be expressible as geometric relationships between geometric objects, which represent physical quantities.
\end{axiom}
%
We will profit from this principle not only to express laws, but also to assess, derive, and interpret them.

\section{Balance law of a conserved quantity}
\label{sec:balance-law-conserved-quantity}
%
\epigraph{Being abstract is something profoundly different from being vague \dotsq\ The purpose of abstraction is not to be vague, but to create a new semantic level in which one can be absolutely precise.}{Edsger Dijkstra}

\begin{definition}
  Refer to a \lingo{continuum} as a region in space.
\end{definition}

\begin{observation}\label{obs:balance-law-conserved-quantity}
  Consider a conserved quantity move through a body. Suppose the body be represented as a \lingo{continuum} $\Omega$ and the quantity $\Phi$, of density $\phi$, be defined for all points in  $\Omega$. Choose now a control region $\omega$ in $\Omega$ bounded by a control surface $\bregion\omega$. Finally, denote by $\flux$ the flux of $\Phi$ across $\bregion\omega$. Then, the evolution of $\Phi$ can be modeled by an \lingo{integral balance law}:
  %
  \begin{equation}\label{eqn:integral-balance-law}
    \odt t\int_{\omega}\phi\,\dvol
    + \oint_{\bregion\omega}\flux\iprod\dsurf
    =
    \int_{\omega}\ssink\,\dvol\,,
  \end{equation}
  %
  where $+\ssink,-\ssink$ represent a \lingo{source density of $\Phi$} and a \lingo{sink density of $\Phi$}.
\end{observation}
%
The integral balance law can be stated in words:~\cite[p. 5]{mishra2016}
%
\begin{law}
  for a conserved quantity moving through a body, the quantity temporal change plus its flux across the body surface equals the total amount of the quantity being consumed or generated inside the body.
\end{law}

\begin{model}
  Consider a physical quantity of density $\phi$ move through a body, as in \cref{obs:balance-law-conserved-quantity}. Then, the evolution of $\phi$ can be modeled by a \lingo{differential balance law in Euler's form}:
  %
  \begin{equation}\label{eqn:differential-balance-law-euler}
    \dt\phi + \div\flux = \ssink\,.
  \end{equation}
\end{model}
%
\begin{argument}
  Since $\phi$ is conserved in the body, depart from \cref{eqn:integral-balance-law}. Differentiate under the volume integral, apply then the divergence theorem to the area integral, gather the resulting integrands into a volume integral, and finally apply the localization theorem to it.
\end{argument}

By changing notation, \cref{eqn:differential-balance-law-euler} can be recasted into its traditional form:
%
\begin{equation}%\label{eqn:differential-balance-law-euler-operator}
  \cpd t\phi + \odiv\flux = \ssink\,.
\end{equation}
%
That is, in words,
%
\begin{law}
  the temporal derivative of a conserved quantity plus the divergence of its flux equals the quantity density of sinks or sources.
\end{law}

An advantage of abstract balance laws, like \cref{eqn:integral-balance-law,eqn:differential-balance-law-euler}, over other approaches lies in their generality:~\cite{thorne2013,mishra2016}
%
\begin{law}
  once a conserved quantity has been chosen, we can derive its \scare{continuity equation} by inserting the relevant physics into the quantity flux $\flux$ and then evaluate its resulting contribution to the law. At each step, one gets out, in the form $\div\flux$, the physics that one puts into $\flux$.
\end{law}
%
Another advantage is the efficiency with which we can generate conservation laws, which are merely specialized versions of the abstract ones.
%
\footnote{For instance, see how laboriously the \scare{continuity equation of mass}, a specialized version of \cref{eqn:differential-balance-law-euler}, is deduced in~\cite[p. 42]{holzbecher2012}.}

\section{Conservation of mass}
\label{sec:conservation-mass}

\begin{model}
  Consider a body deform. Suppose the body be represented as a fluid flowing with velocity $\vel$. Then, the evolution of the fluid density can be modeled by a \lingo{mass continuity equation in Lagrange's form}:
  %
  \begin{equation}\label{eqn:mass-continuity-equation-lagrange}
    \mdt\dens + \dens\div\vel = 0\,.
  \end{equation}
\end{model}
%
\begin{argument}
  Since the fluid mass is conserved and no mass is generated or consumed in the body, depart from a differential balance law, \cref{eqn:differential-balance-law-euler}, with vanishing sinks and sources:
  %
  \begin{equation*}%\label{eqn:mass-continuity-equation-euler}
    \cpd t\dens + \odiv\vat{\dens\vel} = 0\,,
  \end{equation*}
  %
  where $\dens\vel$ represents the fluid mass advective flux.

  Apply then the product rule to the divergence and finally the definition of the material derivative:
  %
  \begin{equation*}
    \omdt t\dens + \dens\odiv\vel = 0\,.
  \end{equation*}
\end{argument}
%
The mass continuity equation \cref{eqn:mass-continuity-equation-lagrange} is often useful in its Euler's form:
%
\begin{equation}\label{eqn:mass-continuity-equation-euler}
  \dt\dens + \div{\dens\vel} = 0\,,
\end{equation}
%
which falls directly from \cref{eqn:differential-balance-law-euler} with $\phi = \dens$, with $\flux = \dens\vel$, and with $\ssink = 0$.

\begin{definition}
  Consider a fluid flow. Call the flow \lingo{incompressible} if and only if the fluid density changes neither in space nor in time.
\end{definition}
%
That is, during incompressible flow, the material derivative of the fluid density vanishes:
%
\begin{equation}\label{eqn:definition-incompressible-flow}
  \mdt\dens = 0\,.
\end{equation}

The following model shows that, during incompressible flow, the divergence of the fluid velocity vanishes.
%
\begin{model}
  Consider a fluid flow. Suppose the flow be represented as incompressible. Then, the fluid velocity can be modeled by a \lingo{incompressible flow equation}:
  %
  \begin{equation}\label{eqn:incompressible-flow-equation}
    \div\vel = 0\,.
  \end{equation}
  %
\end{model}
%
\begin{argument}
  Since the fluid mass is conserved and there are no mass sources neither sinks, depart from \cref{eqn:mass-continuity-equation-lagrange}. Apply the definition of incompressible flow.
\end{argument}
%
Whenever a flow can be modeled as incompressible, it means that the fluid volume is conserved.

\begin{definition}
  In local coordinates $\tbcov i$, define the \lingo{gradient of a tensor $t$} as
  %
  \begin{equation}\label{eqn:covariant derivative}
    \grad t = \tbcov j\tprod\ocder{\tbvec j} t\,.
  \end{equation}
  %
\end{definition}

\begin{theorem}
  In local coordinates $\tbvec i$, the gradient of a vector $\vel$ is given by
  %
  \begin{equation}\label{eqn:gradient-vector-local-coordinates}
    \grad\vel =
    \br{
      \cpd j\tvec\vel i + \tchris ijk\tvec\vel k
    }\tbcov j\tprod\tbvec i\,.
  \end{equation}
\end{theorem}
%
\begin{proof}
  Apply the definition of gradient to $\vel$, express $\vel$ in local coordinates, and perform straightforward tensor calculus operations:
  %
  \begin{align*}
    \grad\vel &= \tbcov j\tprod\ocder{\tbvec j}\br{\tvec\vel i\tbvec i}\,,\\
    %
    &= \tbcov j\tprod\br{
      \tbvec i\ocder{\tbvec j}\tvec\vel i
      + \tvec\vel i\ocder{\tbvec j}\tbvec i
    }\,,\\
    %
    &= \tbcov j\tprod\br{
      \tbvec i\cpd j\tvec\vel i
      + \tvec\vel i\tchris kji\tbvec k
    }\,,\\
    %
    &= \tbcov j\tprod\br{
      \tbvec i\cpd j\tvec\vel i
      + \tvec\vel k\tchris ijk\tbvec i
    }\,,\\
    %
    &= \tbcov j\tprod\tbvec i\br{
      \cpd j\tvec\vel i
      + \tvec\vel k\tchris ijk
    }\,.
  \end{align*}
  %
\end{proof}

\begin{definition}
  In local coordinates $\tbvec i$, the contraction of a unit second rank tensor $\tbcov i\tprod\tbvec j$ is defined as
  %
  \begin{equation}\label{eqn:contraction--unit-second-rank-tensor}
    \cont{\br{\tbcov i\tprod\tbvec j}}
    = \ocont\vat{\tbcov i\tprod\tbvec j}
    = \tbcov i\iprod\tbvec j
    = \tkron ij\,.
  \end{equation}
\end{definition}
%
That is, given a second rank tensor, to contract it means to change the tensor product into an inner product.

\begin{definition}
  Define the \lingo{divergence of a vector} as the contraction of its gradient.
\end{definition}

\section{Cauchy's momentum equation}
\label{sec:cauchy-momentum-equation}

\begin{theorem}
  Consider a scalar field $\phi$ and a vector field $v$. Then, the divergence of their product is given by
  %
  \begin{equation}\label{eqn:divergence-scalar-vector-product}
    \odiv\vat{\phi v} = v\iprod\ograd\phi + \phi\odiv v\,.
  \end{equation}
  %
\end{theorem}
%
\begin{proof}
  By direct application of the product rule.
\end{proof}

The next theorem states the product rule for the material derivative.
%
\begin{theorem}
  Consider a scalar field $\phi$ and the vector fields $u,v$. Then, the material derivative of the product $\phi u$, along $v$, satisfies the \lingo{product rule}:
  %
  \begin{equation}\label{eqn:product-rule-material-derivative}
    \mdt{\phi u} = \mdt\phi u + \phi\mdt u\,.
  \end{equation}
\end{theorem}
%
\begin{proof}
  By definition of material derivative:
  %
  \begin{equation*}
    \omdt t\vat{\phi u} = \cpd t\vat{\phi u} + \ocder v\vat{\phi u}\,.
  \end{equation*}
  %
  Use then the product rule to expand the partials and the directional derivatives:
  %
  \begin{equation*}
    \cpd t\vat{\phi u} + \ocder v\vat{\phi u}
    =
    u\cpd t\phi + \phi\cpd tu + \phi\ocder vu + u\ocder v\phi\,.
  \end{equation*}
  %
  Rearrange the terms of the \acro{rhs} and gather $\phi$ and $u$:
  %
  \begin{equation*}
    \cpd t\vat{\phi u} + \ocder v\vat{\phi u}
    =
    \phi\br{\cpd tu + \ocder vu} + u\br{\cpd t\phi + \ocder v\phi}\,.
  \end{equation*}
  %
  Finally, apply the definition of material derivative to the terms in parentheses.
\end{proof}

\begin{model}
  Consider a body deform. Suppose the body be represented as a continuum. Then, the evolution of the body momentum can be modeled by a \lingo{Cauchy's momentum equation in Lagrange's form}:
  %
  \begin{equation}\label{eqn:cauchy-momentum-equation-lagrange}
    \dens\mdt\vel = \div\stress + \ssink\,,
  \end{equation}
  %
  where $\stress$ represents the continuum stress.
  %
\end{model}
%
\begin{argument}
  Since the continuum momentum is conserved, depart from a differential balance law, \cref{eqn:differential-balance-law-euler}, with $\dens\vel$ as the momentum density; $\dens\vel\vel + \stress$ as the momentum flux; and $\ssink$ as the momentum density consumed or generated in the continuum:
  %
  \begin{equation*}
    \cpd t\vat{\dens\vel} + \odiv\vat{\dens\vel\vel} + \odiv\stress
    = \ssink\,,
  \end{equation*}
  %
  due to the linearity of the divergence.

  Then, expand the temporal derivative and the divergence:
  %
  \begin{equation*}
    \vel\cpd t\dens + \dens\cpd t\vel
    + \vel\vel\iprod\ograd\dens + \dens\vel\iprod\ograd\vel
    + \dens\vel\odiv\vel
    + \odiv\stress
    = \ssink\,.
  \end{equation*}
  %
  Rearrange terms and reckon the \acro{rhs} of the product $\dens\vel$, \cref{eqn:divergence-scalar-vector-product}, to get
  %
  \begin{equation*}
    \vel\br{\cpd t\dens + \odiv\br{\dens\vel}}
    + \dens\br{\cpd t\vel + \vel\iprod\ograd\vel}
    + \odiv\stress
    = \ssink\,.
  \end{equation*}
  %
  See that the first term vanishes due to mass continuity, \cref{eqn:mass-continuity-equation-euler}, and that the second represents the material derivative of the continuum velocity to get
  %
  \begin{equation*}
    \dens\omdt t\vel
    + \odiv\stress
    = \ssink\,.
  \end{equation*}
\end{argument}
%
Note the generality of Cauchy's momentum equation: it models momentum transport in \emph{any} continuum.


\documentclass[11pt]{article}
\usepackage{enumitem}
\usepackage{amsmath}
\begin{document}
\title{MAT1830 --- Assignment 1}
\author{Dylan Pinn --- 24160547}
\maketitle

\section*{Question 1}
Are the following statements true or false? For each, explain why.
\begin{enumerate}[label= (\alph*)]
\item 5 divides 22

	False (because there is no integer $k$ such that $5k = 22$)

\item $14 \equiv 26$ (mod 6)

	True (because 6 divides $26 - 14$)

\item 15 divides 5

	False (because there is no integer $k$ such that $15k = 5$)

\item For any positive integer $n \neq 11, \gcd(11, n) = 1$

	False (because 11 is a prime number and only has the divisors of 1 and 11).

\item There are integers $x, y$ and $z$ such that 15 divides $2^x \times 3^y
  \times 7^z$.

% TODO: Q 1e

\item If $x$ is an integer such that $4x \equiv 12$ (mod 16), then definitely $x
  \equiv 3$ (mod 16)

	$$\gcd(4, 16) = 4$$
	4 divides 12 so there are solutions.

	Divide through by 4 to get $$x \equiv 3 \text{ (mod 16) }$$ which is the
	desired result, so the solution is True

\end{enumerate}

\section*{Question 2}
Use the extended Euclidean algorithm to find integers $x$ and $y$ such that
$356x + 132y = 8$

First use the Euclidean Algorithm to calculate the $\gcd(356,132)$.

\begin{align*}
	356 &= 2 \times 132 + 92 \\
	132 &= 1 \times  92 + 40 \\
	 92 &= 2 \times  40 + 12 \\
	 40 &= 3 \times  12 +  4 \\
	 12 &= 3 \times   4 +  0
\end{align*}

So $\gcd(356,132) = 4$. Now we can use the extended Euclidean algorithm to
calculate $8 = 356x + 132y$. This is easiest if we convert this to be equal the
$\gcd$ of $4$ so we divide it through by 2. Which gives $$4 = 178x + 66y$$

Working back up gives

\begin{align*}
	4 &= 40 - 3 \times 12 \\
	4 &= 40 - 3 \times (92 - 2 \times 40) \\
	4 &= -3 \times 92 + 7 \times 40 \\
	4 &= -3 \times 92 + 7 \times (132 - 92) \\
	4 &= -10 \times 92 + 7 \times 132 \\
	4 &= -10 \times (356 - 2 \times 132) + 7 \times 132 \\
	4 &= -10 \times (356 - 2 \times 132) + 7 \times 132 \\
	4 &= -10 \times 356 + 27 \times 132
\end{align*}

To get this back into the original form of $8 = 356x + 132y$ we need to
multiply through by 2. This gives $$8 = -20 \times 356 + 54 \times 132$$
So $x = -20$ and $y = 54$

\section*{Question 3}
Let $x$ and $y$ be integers such that $x \equiv 4$ (mod 10) and $y \equiv 5$
(mod 10).  Find the integer $z$ such that $48x + 3y^2 \equiv z$ (mod 10) and $0
\leq z \leq 9$.

Substituting $x$ and $y$ into the equation gives

\begin{align*}
	z &\equiv 48(4) + 3(5)^2 \text{ (mod 10) } \\
	z &\equiv 192 + 75 \text{ (mod 10) } \\
	z &\equiv 267 \text{ (mod 10) }
\end{align*}

We are able to take many lots of 10 from this to give
$$z \equiv 7 \text{ (mod 10) }$$ which satisfies the range
$0 \leq z \leq 9$.

\end{document}


%!TEX root = ../main.tex

\chapter{FFTbor Appendix}
\label{ch:fftborapp}

\lhead{FFTbor Appendix}

\section{Full recursions for \texorpdfstring{\emZ{i,j}}{}
for the Turner energy model}
\label{sec:fftbor:turner}

To compute $\emZ{} = \emZ{1,n}$ given input structure \str, we use the recursions

\begin{align}
\label{eq:fftborapp:zx}
\emZ{i,j} = \emZ{i,j-1} \cdot x^{d_0} +
\sum_{\mathclap{\substack{(s_k,s_j) \in \bpSet, \\ i \leq k < j}}}\enspace
\Big( \emZ{i,k-1} \cdot \emZB{k,j} \cdot \boltzE{E_d} \cdot x^{d_1} \Big),
\end{align}

where $d_0 = 1$ if $j$ is base paired
in $\str_{[i,j]}$ and $0$ otherwise, $d_1 =
\dBP{\str_{[i,j]}}{\str_{[i,k-1]} \cup \str_{[k,j]}}$, and $E_d$
is the energy contribution due to dangling ends (energy
contributions from single bases stacking on adjacent base pairs) and
closing AU base pairs (since a non GC base pair closing a stem has a
destabilizing effect).  The sum is taken over all possible
base pairs $(k,j)$ with $i \leq k < j$.

We compute \emZB{} using the recursion

\begin{align}
\label{eq:fftborapp:zbx}
\begin{split}
\emZB{i,j} &= \boltzE{EH(i,j)} \cdot x^{d_2} \\
&+ \sum_{\mathclap{\substack{(s_k,s_l) \in \bpSet, \\ i < k < l < j }}}\enspace
\emZB{k,l} \cdot \boltzE{EI(i,j,k,l)} \cdot x^{d_3} \\
&+ \sum_{\mathclap{\substack{(s_k,s_l) \in \bpSet, \\ i < k < l < j }}}\enspace
\Big( \emZM{i+1,k-1} \cdot \emZB{k,l} \cdot \boltzE{(a+b+c(j-l-1))}
\cdot x^{d_4} \Big)
\end{split}
\end{align}

where $d_2 = \dBP{\str_{[i,j]}}{\{(i,j)\}}$,
$EH(i,j)$ is the energy of the hairpin loop with closing base
pair $(i,j)$, $EI(i,j,k,l)$ is the energy of the stack, bulge or
interior loop with the closing base pair $(i,j)$ and the interior
base pair $(k,l)$, $d_3 = \dBP{\str_{[i,j]}}{\str_{[k,l]} \cup
\{(i,j)\}}$, and $d_4 = \dBP{\str_{[i,j]}}{\str_{[i+1,k-1]} \cup
\str_{[k,l]} \cup\{(i,j)\}}$. The first term in the
recursion takes care of the case where $(i,j)$ is the only base pair
in $[i,j]$, i.e. $(i,j)$ closes a hairpin loop. The second term
handles the case where there is an interior loop (or a bulge or a
stack) closed by $(i,j)$ and $(k,l)$. The third term takes care of
all the structures where $(i,j)$ closes a multiloop. To reduce
complexity of the algorithm, the interior and bulge loop size can be
limited to a maximum size of $L$ (taken by default to be $30$),
by requiring that $l>j-L$ in the above recursion.

The final recursion, for computing \emZM{}, is

\begin{align}
\label{eq:fftborapp:zmx}
\begin{split}
\emZM{i,j} &= \emZM{i,j-1} \cdot \boltzE{c} \cdot x^{d_0} \\
&+ \sum_{\mathclap{\substack{(s_k,s_j) \in \bpSet, \\ i \leq k < j }}}\enspace
\Big( \emZB{k,j} \cdot \boltzE{(b+c(k-i))} \cdot x^{d_5} \\
&+ \emZM{i,k-1} \cdot \emZB{k,j} \cdot \boltzE{b} \cdot x^{d_6} \Big)
\end{split}
\end{align}

where $d_5 = \dBP{\str_{[i,j]}}{\str_{[k,j]}}$ and $d_6
=\dBP{\str_{[i,j]}}{\str_{[i,k-1]} \cup \str_{[k,j]}}$.
Note that since $\emZM{i,j}$ computes the partition function
contribution under the assumption that $[i,j]$ is part of a
multiloop, there will be exactly one stem-loop structure in this
region (the \emZB{} term) or
more than one (the \emZM{}--\emZB{} term).
Justification of recursions (\ref{eq:fftborapp:zx}),
(\ref{eq:fftborapp:zbx}), and
(\ref{eq:fftborapp:zmx})
follow by induction, as in the proof of Theorem \ref{thm:fftbor:recursions}.


For the most part, the abstract semantics applies existing semantic operators of boxed Intervals \cite{COU98}. In this section, we sketch how these operators are used to define the semantics on \adomain.

First of all, $\mathbb{I}$ defines the semantics of arithmetic expressions on a single hypercube by applying the well-known arithmetic operators on intervals.

We use the semantics $\mathbb{I}$ to define the abstract semantics $\mathbb{B}$ of Boolean comparisons. Given a hypercube and a Boolean comparison $E_1 <bop> E_2$ where $<bop> \in \{\geq, >, \leq, <, \neq \}$, $\mathbb{B}$ returns an \emph{abstract value of the boolean domain} (namely, $\mathit{true}$, $\mathit{false}$, or $\top$) comparing the intervals obtained from $E_1$ and $E_2$ through $\mathbb{I}$. Therefore, given a Boolean condition and a set of hypercubes, we partition this set into the hypercubes for which (i) the condition surely holds, (ii) the condition surely does not hold, and (iii) the condition may or may not hold. In this way, we can discard all the hypercubes for which a given Boolean condition surely holds or does not hold.
%Note that in this way we lose some precision. For instance, imagine that in a given hypercube we know that $\statement{x} \in [0..5]$ (because the fixed width of intervals associated to \statement{x} is 5), and we check if $\statement{x} \leq 3$. The answer of $\mathbb{B}$ will be $\top$ and, if the condition was inside an \statement{if} statement, this hypercube will be used to compute the semantics of both the branches. Indeed, we would know that $\statement{x} \in [0..3]$ in the \statement{then} branch, and $\statement{x} \in [4..5]$ in the else branch. Nevertheless, we cannot and do not want to track this information in our hypercube, since the width of the interval associated to \statement{x} is 5, and fixed widths are a key feature in order to obtain an efficient analysis. We will present (Section \ref{sec:widths}) how we can recursively modify the widths of the analysis to improve precision in these cases.\todopietro{Remove it when merging section 6 here - the details about the offset should be presented before and here we should report the formal definitions}
The semantics of the logical operators $not$, $and$, $or$ is defined in the standard way.

$\mathbb{I}$ is used to define the semantics $\mathbb{S}$ of variable assignment as well. The standard semantics of \statement{x=exp} is to (i) obtain the interval representing the right part ($\mathbb{I}\llbracket\statement{x=exp}, \sigma\rrbracket=[m..M]$), and (ii) assign it in the current state. This approach does not necessarily produce a single hypercube, since the interval to assign could have a greater width than the fixed width of the assigned variable (for example, the interval $[0..6]$ when $w=5$). It could also happen that the resulting interval width is smaller than the fixed width, but the interval spans over more than one hypercube side, due to the fixed space partitioning (for example, the interval $[3..6]$ when $w=5$, because the space is partitioned in $[0..5],[5..10]$, etc.). In these cases, we build up several hypercubes that cover the interval $[m..M]$. This can be formalized by $assign(h, V_i, [a..b])=\{h[i\mapsto m] : [m\times w_i .. (m+1)\times w_i]\cap [a..b] \neq \emptyset\}$, where $h$ is a hypercube, $V_i$ is the assigned variable, and $[a..b]$ is the interval we are assigning (which depends on the hypercube $h$, since we use its variables values to compute the result of the expression). We repeat this process for each hypercube $h$ in the abstract state by using it as input for the computation of $assign$.
In this way, we are able to over-approximate the assignment while also keeping the fixed widths of the intervals, which are very important for performance issues.

\vspace{-10pt}
\subsubsection{Offsets}
Offsets allow us to recover some precision when computing the abstract semantics of assignment. In particular, as the expression semantics $\mathbb{I}$ returns intervals of arbitrary widths, we can use such exact result to update the offsets of the abstract state. Formally, the semantics of the assignment is defined as follows:
\begin{equation*}
assign(h, V_i, [a..b]) = \{ h[i\mapsto (m,o_m,o_M)] : [m\times w_i .. (m+1)\times w_i] \cap [a..b] \neq \emptyset \}
\end{equation*}
where $h$ is a hypercube, $V_i$ is the assigned variable, $[a..b]$ is the interval we are assigning and $o_m, o_M$ are computed as:
\begin{equation*}
o_m = \begin{cases}
0 & \mbox{if } a \leq (m \times w_i) \\
a - (m \times w_i) & \mbox{otherwise} \\
\end{cases} \wedge
o_M = \begin{cases}
w_i & \mbox{if } b \geq ((m+1) \times w_i) \\
b - (m \times w_i) & \mbox{otherwise} \\
\end{cases}
\end{equation*}
Note that, when we extract from a hypercube the interval associated to a variable, we use the interval delimited by the offsets, so that abstract operations can be much more precise.

Consider the evaluation of statement \statement{x = x + 0.01} inside a while loop with $1.0$ as width of \statement{x} and $[0..1]$ as initial value of \statement{x}. After the first iteration, the abstract semantics computes $[0.0 .. 1.0]$ and $[1.0 .. 2.0]$ with offsets $[0.01 .. 1.0]$ and $[1.0 .. 1.01]$, respectively. In this way, at the following iteration we would obtain again the same two intervals with the offsets changed to $[0.02 .. 1.0]$ and $[1.0 .. 1.02]$. This results is strictly more precise than the one obtained without offsets, and it is an essential feature of our abstract domain. For instance, in the case study of Figure \ref{lst:casestudy} offsets will allow us to discover if a bouncing ball exits the screen after $N$ iterations of the \statement{while} loop.

\vspace{-10pt}
\subsection{Initialization of the analysis} \label{sec:initialization}
\vspace{-5pt}
Before starting the analysis we have to determine the number of sides each hypercube will have. To do this, we must find all the variables ($Vars$) of the program which are not constants (i.e., assigned only once at the beginning of the program). %To avoid scanning the entire code before starting the analysis,
We require the program to initialize all the variables at the beginning of the program.
%Note that physics simulations, like our case study, satisfy this requirement because they are made up by an initialization of all variables, followed by a \statement{while} loop which contains the core of the program (i.e., the update of the simulated world). Otherwise, we can consider a dummy initialization (i.e., $0.0$) for all variables which are not initialized at the beginning of the program. The actual initialization of the variables will be treated as a normal assignment, without any loss of precision.
The initialization of the analysis is made in two steps. First, for each initialized variable, we compute its abstraction in the non-relational domain chosen to represent the single variables. The resulting set of abstract values could contain more than one element. Let us call $\alpha(V)$ the set of abstract values associated to the initialization of the variable $V \in Vars$. Then we compute the Cartesian product of all sets of abstracted values (one for each variable). The resulting set of tuples (where each tuple has the same cardinality as $Vars$) is the initial set of hypercubes of the analysis.
Formally, $\adomain = \sbigtimes_{V \in Vars} {\alpha(V)}$.

Consider the code of our case study in Figure \ref{lst:casestudy}. First of all, we must identify the variables which are not constants: $dt,g,k$ are assigned only during the initialization, so we do not include them in $Vars$. The set of not-constant variables is then $Vars = \{ V_1 = px, V_2 = py, V_3 = vx, V_4 = vy \}$, and so $|Vars| = 4$.
%Suppose that the widths associated to the variables are  $w_1 = 10.0, w_2 = 25.0, w_3 = 30.0, w_4 = 5.0$. Then, the abstraction of each variable is $\alpha(V_1) = \{ 0 \}$, $\alpha(V_2) = \{ 0, 1 \}$, $\alpha(V_3) = \{ 0, 1 \}$, and $\alpha(V_4) = \{ -6 \}$.
%The Cartesian product of these abstractions brings us to the following initial set of hypercubes:
%$$\adomain = \{ (0,0,0,-6) , (0,0,1,-6) , (0,1,0,-6) , (0,1,1,-6) \}$$

\vspace{-10pt}
\subsection{Tracking the origins}\label{sec:origins}
\vspace{-5pt}
During the analysis of a program we also track, for each hypercube of the current abstract state, the initial hypercubes (\textit{origins}) from which it is derived. To store such information, we proceed as follows. Let $H_i$ be the set of hypercubes obtained for the $i$-th statement of the program. The data structure of a hypercube $h$ contains also an additional set of hypercubes, $h^{or}$, which are its origins and are always a subset of the initial set of hypercubes, i.e., $\forall h : h^{or} \subseteq H_0$. At the first iteration, each hypercube contains only itself in its origins set: $\forall h \in H_0 : h^{or} = \{ h \}$. When we execute a statement of the program, each hypercube produces some new hypercubes: at this stage, the origins set is simply propagated. For example, if $h$ generates $h_1,h_2$, then $h_1^{or} = h_2^{or} = h^{or}$. When merging all the newly produced hypercubes in a single set (the abstract state associated to the point of the program just after the executed statement), we also merge through set union the sets of origins of any repeated hypercube. For example, consider $H_i = \{ h_a, h_b \}$ and let $h_1,h_2$ be the hypercubes produced by $h_a$ executing statement $i$-th and $h_2,h_3$ be those produced by $h_b$. Then, $H_{i+1} = \{ h_1,h_2,h_3\}$ and $h_1^{or} = h_a^{or}$, $h_2^{or}= h_a^{or} \cup h_b^{or}$ and $h_3^{or} = h_b^{or}$.

\vspace{-10pt}
\subsection{Width choice} \label{sec:widths}
\vspace{-5pt}
The choice of the interval widths influences both the precision and efficiency of the analysis. On the one hand, if we use smaller widths we certainly obtain more precision, but the analysis risks to be too slow. On the other hand, with bigger widths the analysis will be surely faster, but we could not be able to verify the desired property. To deal with this trade-off, we implemented a recursive algorithm which adjusts the widths automatically.
We start with wide intervals (i.e., coarse precision, but fast results) and we run the analysis for the first time. At the end of the analysis, we check, for each hypercube of the \emph{final} set, if it verifies the desired property. We then associate to each \emph{origin} (i.e., initial hypercube) its final result by merging the results of its derived final hypercubes (we know this relationship because of the origins set stored in each hypercube): some origins will certainly verify the property (i.e., they produce only final hypercubes which satisfy the property), some will not, and some will not be able to give us a definite answer (because they produce both hypercubes which verify the property and hypercubes which do not verify it). We partition the starting hypercubes set with respect to this criterion (obtaining, respectively, the \emph{yes} set, the \emph{no} set and the \emph{maybe} set), and then we run the analysis again with halved widths, but \emph{only} on the origins which did not give a definite answer (the \emph{maybe} set). This step is only performed until we reach a specific threshold, i.e., the \textit{minimum width} allowed for the analysis. The smaller this threshold is, the more precise (but slower) the analysis becomes.

%At the end of this recursive process, we obtain three partitions of the variable space: a set of starting hypercubes which certainly verify the property (\emph{yes} set), a set of starting hypercubes which certainly do not verify the property (\emph{no} set), and a set of starting hypercubes which, at the minimum width allowed for the analysis, still do not give a definite answer (\emph{maybe} set).
The analysis is then able to tell us which initial values of the variables bring us to verify the property (the union of all the \emph{yes} sets encountered during the recursive algorithm) and which do not. Thanks to these results, the user can modify the initial values of the program, and run the analysis again, until the answer is that the property is verified \emph{for all initial values}. In our case study, for example, we can adjust the possible initial positions and velocities until we are sure that the ball will exit the screen in a certain time frame.

The formalization of this recursive algorithm is presented in Algorithm \ref{alg:widthAdjusting}.

\begin{algorithm}
\caption{The width adjusting recursive algorithm} \label{alg:widthAdjusting}
\begin{algorithmic}
\Function {Analysis} {$currWidth, minWidth, startingHypercubes$}
  \State \Return $(yes \cup yes', no \cup no', maybe')$
  \State \textbf{where}
    \State $(yes, no, maybe) = hypercubesAnalysis(currWidth, startingHypercubes )$
    \If {$currWidth/2.0 \geq minWidth$}
      \State $(yes', no', maybe') = Analysis(currWidth/2.0, minWidth, maybe)$
    \Else
      \State $(yes', no', maybe') = (Set.empty, Set.empty, maybe)$
    \EndIf
\EndFunction
\end{algorithmic}
\end{algorithm}

%The overall analysis takes as input the starting width, the minimum width allowed and the set of starting hypercubes (obtained from the initialization of the program as described in Section \ref{sec:initialization}). It executes the analysis on such data with the function \statement{hypercubesAnalysis}, which returns three sets of hypercubes (\statement{yes,no,maybe}) with the meaning explained above. Then, if the halved width is still greater than the minimum one allowed, the algorithm performs a recursive step by repeating the analysis function only on the \statement{maybe} hypercubes set (with halved width).

%Note that %the initial hypercubes sets
%the three final hypercubes sets (the \emph{yes,no,maybe} partitions)
%will contain hypercubes of different sizes: this happens because each hypercube can come from a different iteration of the analysis, and each iteration is associated to a specific hypercube size. A certain portion of the variable space could give a definite answer even at coarse precision (for example, when the horizontal velocity of the ball is sufficiently high, the values of other variables do not matter so much), while another portion could need to be split in much smaller hypercubes to give interesting results.

%\todogiulia{Tino: come dicevo questa sezione si dovrebbe ridurre all'osso: riferimenti a Intervalli, Disjuctinve domains trough Powerset, Prodotto Cartesiano, Conditional Partitioning}
%
%In this Section, we define the abstract semantics of Hypercubes. In particular, the semantics we will define are the following ones:
%\begin{itemize}
%\item $\mathbb{I}$, the abstract semantics of arithmetic expressions, which receives an expression and a single hypercube in input and returns an \emph{interval of real values} resulting from the execution of that expression when the variable values belong to that hypercube.
%\item $\mathbb{B}$, the abstract semantics of boolean conditions, which receives a single hypercube and two expressions in input and returns an \emph{abstract value of the boolean domain} (namely, $true$, $false$, or $\top$) obtained by comparing the two expressions (through $\geq, >, \leq, <$ or $\neq$) when the variable values belong to that hypercube. Boolean conditions can be combined through logical operators (and, or, not) in the usual way (i.e., exploiting the abstract semantics of the boolean abstract domain).
%\item $\mathbb{S}$, the abstract semantics of statements, which receives in input a set of hypercubes (the current abstract state) and returns a new set of hypercubes (the new abstract state after the execution of the statement).
%\end{itemize}
%
%\subsection{The abstract semantics of arithmetic expressions, $\mathbb{I}$}
%
%\subsubsection{Constants}
%\label{sec:constants}
%We define a constant as a variable which gets assigned only once with a constant value, or a numerical value which appears in some statements (without being assigned to a specific variable). To simplify the treatment of constants, we execute a preprocessing on the program with constant propagation, to remove constant variables and replace their uses with their numerical value.
%
%
%The abstract semantics of an expression made up by a constant numeric value is, simply, an interval of zero width: the extremes of the interval are the same and they are equal to the value of the constant.
%Then, the abstract semantics of a constant is:
%
%$$\mathbb{I}\llbracket c \rrbracket \; h = [c,c]$$
%
%Note that the value of the hypercube in input ($h$) is i,nored because it is not needed to compute the result.\ nn
%
%\subsubsection{Intervals}
%The abstract semantic of an expression made up by an interval of real values is immediate: it is exactly that interval, without modifications. We ignore the hypercube passed in input.
%
%$$\mathbb{I}\llbracket (m,M) \rrbracket \; h = [m,M]$$
%
%\subsubsection{Variables}
%When the expression is made up by a variable, we must consider the abstract value of that variable in the hypercube passed in input. Let $h_i$ be the integer index associated to the $i$-th dimension of the hypercube, $V_i$ the $i$-th variable defined in the program and $w_i$ the width associated in the analysis to such variable. Then, the abstract semantics of a variable  is $\mathbb{I}\llbracket V_i\rrbracket \; h = [h_i*w_i,(h_i+1)*w_i]$.
%
%
%\subsubsection{Arithmetic operations}
%We considered only the most used arithmetic operators. In particular, we considered sum ($+$), subtraction ($-$), product ($\times$) and division ($\div$). These operators should suffice for most physics simulations (for example, our case study requires only sum and product - the change of sign being a multiplication for $-1$). Anyway, our framework can be easily extended to support other operations (for example modulus), by simply defining their abstract semantics when working on intervals of values.
%
%The semantics of these operators over intervals has been already deeply studied, and we refer to \cite{COU98} for their definitions.
%
%
%\subsection{The abstract semantics of Boolean conditions, $\mathbb{B}$}
%\label{sec:boolcondition}
%We now define the semantics of integer comparison using the operators $>$, $<$, $\leq$, $\geq$, and $\neq$.
%
%The abstract semantics separately computes the semantics on the left and right arithmetical expressions of the statement, obtaining two intervals. Let us call them $i_1 = [a,b]$ and $i_2 = [c,d]$. The abstract comparison between them depends on the specific comparison operator present in the statement:
%\begin{itemize}
%\item $i_1 \neq i_2$ returns true if $b < c \vee a > d$, false if $b=c=a=d$, and $\top$ otherwise.
%\item $i_1 < i_2$ returns true if $b < c$, false if $a > d$, top otherwise.
%\item $i_1 > i_2$ returns true if $a > d$, false if $b < c$, top otherwise.
%\item $i_1 \leq i_2$ returns true if $b \leq c$, false if $a \geq d$, top otherwise.
%\item $i_1 \geq i_2$ returns true if $a \geq d$, false if $b \leq c$, top otherwise.
%\end{itemize}
%
%$\mathbb{B}$ will be used by the statement semantics $\mathbb{S}$ when computing the semantics of \statement{if} and \statement{while} statements to discard the hypercubes that surely do not satisfy the condition. Note that in this way we lose some precision. For instance, imagine that in a given hypercube we know that $\statement{x} \in [0..5]$ (because the fixed width of intervals associated to \statement{x} is 5), and we check if $\statement{x} \leq 3$ when computing the semantics of an \statement{if} statements. The answer of $\mathbb{B}$ will be $\top$, and so this hypercube will be used to compute the semantics of both the branches. Indeed, we would know that $\statement{x} \in [0..3]$ in the \statement{then} branch, and $\statement{x} \in [4..5]$ in the else branch. Nevertheless, we cannot track this information in our hypercube, since the width of the interval associated to \statement{x} is 5. Anyway, we will present (Section \ref{sec:widths}) how we can recursively modify the widths of the analysis to improve precision in these cases.
%
%
%\subsection{The abstract semantics of statements, $\mathbb{S}$}
%
%\subsubsection{Assignment}
%Usually, with non-disjunctive domains, the abstract semantics of an assignment is straightforward: you have to compute the abstract semantics of the expression and update the abstract value of the variable with the result. In our domain, though, we track a different kind of information: we represent possible values of all variables together (through hypercubes) and we consider disjunctive information (a set of valid hypercubes instead of a single hypercube). Therefore, we must devise a specific abstract semantics to deal with the assignment statement.
%
%Let the assignment be $V_i = e$, where $e$ is an arithmetic expression. Our approach can then be sketched as follows:
%\begin{itemize}
%\item we consider, separately, each hypercube $h$ of the current state;
%\item we compute the abstract semantics of the arithmetic expression $e$ passing to it the hypercube $h$.
%\item we create a new hypercube (or \emph{some} new hypercubes, depending on the width of the resulting interval), where the abstract value of $V_i$ is the abstraction of the interval resulting from $e$.
%\end{itemize}
%
%If the interval obtained from $e$ overlaps over several partitions established for variable $V_i$, we have to build up several hypercubes as result of the assignments semantics over a single hypercube.
%
%
%On the other hand, if many hypercubes of the initial state map to the same hypercube in the resulting state, it could also happen that the cardinality of \adomain\ decreases (or remains unmodified) after the execution of an assignment.
%
%Formally:
%
%$$\mathbb{S}\llbracket \statement{V_i = e}\rrbracket \; H = \bigcup_{h \in H} {assign(h, V_i, \mathbb{I}\llbracket e\rrbracket \; h)}$$
%
%where $assign(h, V_i, [a,b])=\{h[i\mapsto m] : [m\times w_i .. (m+1)\times w_i]\cap [a..b] \neq \emptyset\}$. The output of this function is the set of hypercubes covering all the intervals that overlaps with the interval assigned to the given variable.
%
%
%\subsubsection{If-then-else semantics}
%
%To precisely deal with branches of \statement{if} statements, we partition the abstract state \adomain\ with respect to the evaluation of the branching condition. In particular, we compute the abstract semantics $\mathbb{B}$ of the boolean condition on each hypercube of \adomain\ and we assign each hypercube to a specific partition, based on the result of the condition semantics. Therefore, we obtain three partitions: the hypercubes for which the condition evaluates to true ($p_t$), the ones for which the condition evaluates to false ($p_f$), and the ones for which we do not have a definitive answer ($p_\top$).
%
%Once obtained these three partitions, we can compute selectively the abstract semantics of the two branches, and in particular the \statement{then} branch with $p_t \cup p_\top$, and the \statement{else} branch with $p_f \cup p_\top$.
%
%Formally, the semantics of the \statement{if} statements follows:
%
%$$\mathbb{S}\llbracket \statement{if}(B)\ \statement{then}\ P_1\ \statement{else}\ P_2\rrbracket \; H = ( \mathbb{S}\llbracket P_1\rrbracket \; (p_t \cup p_\top) ) \cup ( \mathbb{S}\llbracket P_2\rrbracket \; (p_f \cup p_\top) )$$
%
%where $p_t = \{ h \in H : \mathbb{B}\llbracket \ael{if}\rrbracket \; h = true \}$, $p_f = \{ h \in H : \mathbb{B}\llbracket \ael{if}\rrbracket \; h = false \}$, and $p_\top = \{ h \in H : \mathbb{B}\llbracket \ael{if}\rrbracket \; h = \top \}$.
%
%\subsubsection{Concatenation of statements}
%The abstract semantics of the concatenation of two statements is straightforward: it executes the abstract semantics of the first statement, it takes the result and it passes it as input to the abstract semantics of the second statement. Formally:
%
%$$\mathbb{S}\llbracket P_1;P_2\rrbracket \; H = \mathbb{S}\llbracket P_2\rrbracket \; (\mathbb{S}\llbracket P_1\rrbracket \; H)$$
%
%\todogiulia{Non sono per niente convinto che sia questa big-step semantics quello di cui abbiamo bisogno. Ad esempio, la semantics di \statement{while(true) P_1; P_2} ritorna $\emptyset$ stando a questa definizione. A occhio abbiamo bisogno di qualcos'altro, e.g., uno stato astratto per ogni punto di programma di un cfg? In questo caso, non dobbiamo lavorare a questo livello con \statement{if} e \statement{while} ma piu' a basso livello.}
%
%\subsection{While loop}
%To do.


\subsection{Generative Adversarial Networks (GANs)}

\subsubsection{Introduction}

\subsubsection{The GAN generator}

Generator: take latent multivar normal as input layer

Output of generator is of same dimension as input iamges

Generative NN: need probability distribution on input layer

Generator typically deconvolutional

Downside of gan. only discriminates between real and fake.

\subsubsection{The GAN discriminator}

Discriminator: use normal CNN for deep


\chapter{Prospective Solution}

\section{Pre-Processing of Input Data}
Before going through with the problem resolution and trying to find the shortest path for the vehicles, we opt to pre-process the graph, making the other tasks easier.

\begin{itemize}
    \item calculating the shortest paths for all pairs of nodes in a certain radius of the company's garage through use of Floyd-Warshall's algorithm. This will allow the shortest paths between most used nodes to already be calculated, speeding up the calculation of itineraries
    \item evaluating the connectivity of the graph through the Tarjan's algorithm,  followed by removal of the irrelevant elements
\end{itemize}

\section{Problem Identification}

With the graph and the orders pre-processed, there's now a need to find the most efficient way for the vehicles to pick up and deliver the costumers' orders. Before, we have divided the problem into four problems:
\begin{itemize}
    \item \textbf{I} - Calculation of the itineraries
    \item \textbf{II} - Inclusion of recharging points in the paths as needed
    \item \textbf{III} - Evaluation of the graph's connectivity
    \item \textbf{IV} -Distribution of the orders between the vehicles available to the company
\end{itemize}

\section{Solutions}

\subsection{Problem I - Itineraries/Routes Calculation}
Although most relevant pairs of nodes already have their shortest path calculated, some pick up or delivery points might be out of bound for the pre-processing calculations. For these and other special cases, we deemed Bidirectional Dijkstra with implementation of A* algorithm the best option. This choice was made considering the speed of the algorithm and the fact that the destination node is supposedly always known.

The itinerary for a vehicle is calculated having into account the shortest paths between the interest points of his orders (and the recharge points). The algorithm to perform this task will most likely implement a backtracking strategy, in case autonomy is a problem.

\subsection{Problem II - Autonomy/Range}
To tackle this problem, we use the following strategy:
\begin{enumerate}
    \item Before every assignment of a vehicle to a certain path, its current range must be evaluated.
    \item If the value is not enough for the voyage, the vehicle must localize one or more recharge points. The criteria to find the best points is to choose the recharge point closest to both the starting and the finishing node
    \item If the value is enough, it must also be checked if the vehicle has enough autonomy to get to a recharge point after the path
    \item If both 2. and 3.'s  answers are positive, it is safe to proceed. Else, recharge point must be included in his itinerary
    \item If there are no recharge points available in the conditions, the itinerary is aborted
\end{enumerate}

\subsection{Problem III - Connectivity}
Tarjan's algorithm was our choice to solve the connectivity problem. By checking the connectivity of the graph, we can check for any nodes that are not accessible, supposedly due to road work, accidents or other unexpected events. We chose Tarjan's because it presents itself as the fastest option from the ones we analysed.

\subsection{Problem IV - Orders Distribution}
The distribution of orders by the vehicles is by far the most challenging subproblem. This is a Route Optimization problem. Our solution for it was not optimal, yet we made an effort to make the result the best possible. We solved this problem by dividing the pick up points (representing each a different order) into $|V|$ different groups, where $|V|$ is the number of vehicles available. We do this using the Agglomerative Hierarchical Clustering described in the previous section.

\subsection{General}
In sum, our solution:
\begin{enumerate}
    \item Pre-Processing of the graph in terms of shortest paths and connectivity
    \item Ditribution of Orders into groups
    \item Calculation of the best route for each group (which represents a vehicle's orders)
    \begin{itemize}
        \item Use of the shortest paths pre-calculated or calculate new ones if necessary
        \item Try the best route; if autonomy deems into impossible at any point, rewind until you can change a decision (backtracking)
    \end{itemize}
\end{enumerate}
\uline{Note:} The algorithms and solutions presented may not be the exact same to be used, they only represent an estimation. In the second part of this work, the algorithms will be tested and some changes may be necessary.


\documentclass[11pt]{article}
\usepackage{amsmath}
\usepackage{amsfonts}
\begin{document}

\title{APPM 5510 HW3}
\author{Zane Jakobs}
\date{}
\maketitle
\subsection*{1} With the notation $x_0^0$ representing the first element of $x_0$, we know from the values of $y$ that $x_0^0 + x_0^1 = 1,$ and that $x_1^0 + x_1^1 = 0$, and from the definition of the system that $x_1^0 = -x_0^0 + x_0^1$ and $x_1^1 = 2x_0^0 + x_0^1$. We plug these definitions into the equations generated by our observed data to get
\[
2x_0^1 = -x_0^0
\]
and thus
\[
\frac{1}{2} x_0^0 = 1- x_0^0 \implies x_0^0 = 2.
\]
We then have $x_0^1 = -\frac{1}{2} x_0^0 = -1,$ so $x_0 = (2,-1)^T.$
\subsection*{2} The controllability matrix
\[
[V] = \begin{bmatrix} 1 & 0\\  1 &0\end{bmatrix}
\]
does not have full row rank, so no, the system is not controllable.
\subsection*{3}
The Kalmain gain matrix here is
\[
K = B\delta \dfrac{1}{\delta\cdot B \cdot \delta + \gamma^2} = \dfrac{\delta B}{\delta^2 B + \gamma^2}\tag{1}
\]
and the posterior KF covariance at some time $t$ is
\[
C_t = (1-\delta K)B_t\tag{2}.
\]
Now, the background covariance updates as
\[
B_{t+1} = \lambda^2 C_t + \sigma^2, \tag{3}
\]
so by plugging (1) and (3) into (2), we get an update formula for the KF covariance:
\[
C_{t+1} = \left( 1  - \dfrac{\delta^2(\lambda^2 C_t +  \sigma^2)}{\delta^2(\lambda^2 C_t + \sigma^2) + \gamma^2}\right) (\lambda^2 C_t + \sigma^2).\tag{4}
\]
We then seek a fixed point of $C_t$ (by replacing $C_t$ and $C_{t+1}$ in (4) with just $C$ and solving algebraically) such that we can evaluate the limit as $\delta\to 0$ in the infinite-time limit. However, if we exchange the order of the limits (which, due to the linearity of limits, we can do if both limits exist), we see that
\[
\begin{aligned}
C &=  \left( 1  - \dfrac{0\cdot(\lambda^2 C +  \sigma^2)}{0\cdot(\lambda^2 C + \sigma^2) + \gamma^2}\right) (\lambda^2 C + \sigma^2)\\
&= \lambda^2 C + \sigma^2 \implies C = \dfrac{\sigma^2}{1-\lambda^2}.
\end{aligned}
\]
Thus, we see that the limiting value of $C$ does not depend at all on the properties of our observations, which makes sense because as $\delta\to 0$, the signal-to-noise ratio of our observations also goes to zero, and the system becomes non-observable. In such a non-observable system, the only factors that control the KF posterior covariance can come from our knowledge of the system dynamics, not our observations (which we cannot trust at all in this non-observable limit).
\subsection*{4(a)} The observability matrix,
\[
\begin{bmatrix}
1 & 0\\
\lambda & 0
\end{bmatrix}
\]
does not have full column rank, so no, this system is not observable.
\subsection*{4(b)} Assuming the i.i.d. $\eta_j$ have variance $\sigma^2$, the controllability matrix,
\[
[AV\ V] = \begin{bmatrix}
\lambda\sigma & 0 & \sigma & 0 \\
\sigma & 0 & 0 & 0
\end{bmatrix}
\]
has full row rank, so yes, the system is controllable.

\subsection*{4(c)} Since the observation operator selects only the more recent entry (e.g. $Hw_j = x_j$), the Kalman smoother's posterior variance updates as
\[
[C_{j-1} | C_j] = B_{j-1} - AB_{b-1} H^T(HB_jH^T + R)^{-1} HB_{j-1}A^T = B_{j-1} - \dfrac{(\lambda B_{j-1})^2}{B_j + \gamma^2}.
\]
Using the background covariance update formula from problem (3), we have a posterior smoother variance of
\[
[C_{j-1} | C_j] = (\lambda^2 C_{j-2} + \sigma^2)\left( 1 - \dfrac{\lambda^2 (\lambda^2 C_{j-2} + \sigma^2)}{\lambda^2 C_{j-1} + \sigma^2 + \gamma^2}\right).
\]
Seeking a fixed point of $C$, we end up at the equation $g(C) = C,$ where
\[
g(C) =  (\lambda^2 C + \sigma^2)\left( 1 - \dfrac{\lambda^2 (\lambda^2 C + \sigma^2)}{\lambda^2 C + \sigma^2 + \gamma^2}\right).
\]
Now, from LSZ 4.4.1, we know that the posterior variance of the first entry, which has update function
\[
g_{4.4.1}(C) =  (\lambda^2 C + \sigma^2)\left( 1 - \dfrac{(\lambda^2 C + \sigma^2)}{\lambda^2 C + \sigma^2 + \gamma^2}\right),
\]
converges, so there does exist a solution to $g_{4.4.1}(C) = C$. Now, if $|\lambda | < 1$, then $g(C)$ gets closer (than $g_{4.4.1}(C)$) to equalling $\lambda^2 C + \sigma^2$ on iteration, as the portion of $g(C)$ in parentheses approaches 1 as $|\lambda |\to 0$ faster than that of $g_{4.4.1}(C)$, so by direct comparison, iterations of $g$ must converge in this case. If $|\lambda | = 1$ exactly, $g = g_{4.4.1}$, so since $g_{4.4.1}$ converges, $g$ must as well (since they are equal everywhere). Now, if $|\lambda | > 1$, since the part of $g$ in parentheses must be positive semi-definite (in order for it to sensibly represent a covariance), increasing $|\lambda |$ increases the negative part of that quantity, driving the term in parentheses to zero. Thus, since making $|\lambda |$ large makes $g$ smaller than if $|\lambda | \leq 1$, iterations of $g$ again must converge by direct comparison to $g_{4.4.1}$.

\end{document}


\documentclass{article}
\usepackage{fullpage}
\usepackage{nopageno}
\usepackage{amsmath}
\allowdisplaybreaks

\newcommand{\abs}[1]{\left\lvert #1 \right\rvert}
\newcommand{\degree}{\ensuremath{^\circ}}

\begin{document}
Jon Allen

October 23, 2013

\section*{4.3}
only need the "form" of the particular solution for 14,20,24. Need the particular solution for 30. Don't forget we need the homogeneous solution too for form of solution.

\subsection*{\#14}
\[y''-4y'+3y=-e^{-9t}\]
\subsubsection*{solution}
\begin{align*}
	r^2-4r+3&=0=(r-3)(r-1) & r&=1,3 & y_h&=c_1e^{t}+c_2e^{3t}\\
	f(t)&=-e^{-9t} & S_p&=\{e^-9t\} & y_p&=Ae^{-9t}
\end{align*}

\subsection*{\#20}
\[y''+4y=4\cos t-\sin t\]
\subsubsection*{solution}
\begin{align*}
	r^2+4&=0 & r&=\frac{-0\pm\sqrt{0^2-4\cdot1\cdot4}}{2\cdot1}=\frac{\pm4i}{2}=\pm2i & y_h&=c_1\cos 2t+c_2\sin 2t \\
	f(t)&=4\cos t-\sin t & S&=\{\cos t,\sin t\}\cup\{\cos t,\sin t\}=\{\cos t,\sin t\} & y_p&=A\cos t+B\sin t
\end{align*}

\subsection*{\#24}
\[y''-4y'+13y=2te^{-2t}\sin 3t\]
\subsubsection*{solution}
\begin{align*}
	r^2&-4r+13=0 & r&=\frac{4\pm\sqrt{16-4\cdot1\cdot13}}{2}=2\pm3i & y_h&=e^{2t}\left(c_1\cos 3t+c_2\sin 3t\right)\\
	f(t)&=2te^{-2t}\sin 3t & S&=\left\{e^{-2t}\sin 3t,e^{-2t}\cos 3t,te^{-2t}\sin 3t,te^{-2t}\cos 3t\right\}
\end{align*}
\[y_p=Ae^{-2t}\sin 3t+Be^{-2t}\cos 3t+Cte^{-2t}\sin 3t+Dte^{-2t}\cos 3t\]

\subsection*{\#30}
find a general solution to $y''+3y'-4y=-32t^2$
\subsubsection*{solution}
\begin{align*}
	r^2+3r-4&=0=(r-1)(r+4) & r&=1,-4 & y_h&=c_1e^t+c_2e^{-4t}\\
	f(t)&=-32t^2 & y_p&=A+Bt+Ct^2 & {y_p}'&=B+2Ct \quad {y_p}''=2C
\end{align*}
\[2C+3B+6Ct-4A-4Bt-4Ct^2=(2C+3B-4A)+t(6C-4B)-4Ct^2=-32t^2\]
\begin{align*}
	-4C&=-32 & C&=8 & 6C-4B&=0 & B&=12 & 2C+3B-4A&=0 & \frac{52}{4}&=A=13
\end{align*}
\[y=c_1e^t+c_2e^{-4t}+8t^2+12t+13\]
\section*{4.4}

\subsection*{\#23}
find a general solution to $y''+6y'+9y=t^{-1}e^{-3t},t>0$
\subsubsection*{solution}
\begin{align*}
	r^2+6+9&=0=(r+3)^2 & r&=-3 & y_h&=c_1e^{-3t}+c_2te^{-3t}\\
	W&=e^{-3t}(e^{-3t}-3te^{-3t})+te^{-3t}3e^{-3t} & W&=e^{-6t} & {u_1}'&=-\frac{te^{-3t}}{te^{3t}e^{-6t}}=-1 \\
	{u_2}'&=\frac{e^{-3t}}{te^{3t}e^{-6t}}=t^{-1} & \int{{u_1}'\,\mathrm{d}t}&=-t & \int{\frac{1}{t}\,\mathrm{d}t}&=\ln{\abs{t}},t>0\rightarrow\ln t
\end{align*}
\[y=e^{-3t}\left(c_1+c_2t-t+t\ln t\right)=e^{-3t}\left(c_1+c_3t+t\ln t\right)\]

\subsection*{\#28}
find a general solution to $y''-10y'+25y=e^{5t}\ln 2t, t>0$
\subsubsection*{solution}
\begin{align*}
	r^2&-10r+25=0=(r-5)^2 & r&=5 & y_h&=c_1e^{5t}+c_2te^{5t}\\
	W&=e^{5t}\left(5te^{5t}+e^{5t}\right)-te^{5t}5e^{5t} & W&=e^{10t} & {u_1}'&=-\frac{te^{5t}e^{5t}\ln 2t}{e^{10t}}=-t\ln 2t\\
	{u_2}'&=\frac{e^{5t}e^{5t}\ln 2t}{e^{10t}}=\ln 2t & -\int{t\ln 2t\,\mathrm{d}t}&=-z_1w_1+\int{w_1\,\mathrm{d}z_1} &&
	\begin{aligned}
		z_1&=\ln 2t & \mathrm{d}w_1&=t\,\mathrm{d}t\\
		\mathrm{d}z_1&=\frac{1}{t}\mathrm{d}t & w_1&=\frac{1}{2}t^2
	\end{aligned}\\
	u_1&=-\frac{1}{2}t^2\ln 2t+\frac{1}{2}\int{t\,\mathrm{d}t} & u_1&=\frac{1}{2}t^2\left(\frac{1}{2}-\ln 2t\right) & \int{\ln 2t\,\mathrm{d}t}&=z_2w_2-\int{w_2\mathrm{d}z_2}\\
	&\begin{aligned}
		z_2&=\ln 2t & \mathrm{d}w_2&=\mathrm{d}t\\
		\mathrm{d}z_2&=\frac{1}{t}\mathrm{d}t & w_2&=t
	\end{aligned} &
	u_2&=t\ln t 2t-\int{\mathrm{d}t} & u_2&=t\ln 2t-t
\end{align*}
\begin{align*}
	y&=e^{5t}\left(c_1+c_2t+\frac{1}{2}t^2\left(\frac{1}{2}-\ln 2t\right)+t^2\ln 2t-t^2\right)\\
	y&=e^{5t}\left(c_1+c_2t+\frac{1}{2}t^2\ln 2t-\frac{3}{4}t^2\right)
\end{align*}
\end{document}


\input{./fig/tikzsettings}
\maketitle

\section*{Preface}
%\input{../preface}

These notes compile information from various sources, which should be
consulted for more details on particular subjects. These are in
particular the books by Daniele Boffi, Franco Brezzi, and Michel
Fortin~\cite{BoffiBrezziFortin13} and by Alexandre Ern and Jean-Luc
Guermond~\cite{ErnGuermond04} on the general theory of mixed finite
elements, the books by Dietrich Braess~\cite{Braess97,Braess13} and
Philippe Ciarlet~\cite{Ciarlet88} on elasticity, the book by Vivette
Girault and Pièrre-Arnaud Raviart~\cite{GiraultRaviart86} on
incompressible fluids, the book by Peter Monk~\cite{Monk03}, and the
works by Douglas Arnold, Richard Falk, and Ragnar
Winther~\cite{ArnoldFalkWinther06acta,ArnoldFalkWinther10} on the
finite element exterior calculus.

Special thanks go to Dr.~Daniel Arndt for contributing problems,
solutions, and improving the notes at many points. Furthermore, I
thank Vladislav Olkhovskiy and Saurabh Mehta for valuable corrections
and additions.
\thispagestyle{empty}
\setcounter{page}{0}

\tableofcontents

\chapter{From elliptic to mixed problems}
We begin our course of mixed finite element methods by studying a
vector-valued elliptic problem. Then, we study its dependence on its
parameters and naturally arrive at a mixed formulation. We derive a
few properties of mixed systems and then turn our attention to the
first example: the Stokes equations of incompressible flow. We close
the chapter by considering mixed systems as first order conditions
for constrained minimization problems.

\input{mixedintro}
\input{lagrange}

\chapter{Conditions for well-posedness}
\label{sec:mixed-wellposedness}
In this chapter, we will first modify conditions for well-posedness in
finite dimensions from positive definiteness to the general case. In
particular, we will derive a quantitative formulation, which we will
study for infinite dimensional problems in the second section. In the
third section, we derive the inf-sup condition for mixed problems as a
special case.
\input{infsup}

\chapter{The Stokes problem}
\label{cha:stokes}
\input{stokes}

\chapter{Mixed formulation of elliptic problems}
\label{cha:darcy}
\input{darcy}

\chapter{Divergence conforming discontinuous Galerkin methods}
\label{cha:hdivdg}
\input{hdivdg}

\chapter{Maxwell's equations and the de Rham complex}
\section{Maxwell's equations}
\label{cha:maxwell}
\input{maxwell}

\section{The de Rham complex}
\label{cha:derham}
\input{derham}

\printbibliography
\printindex

%%% Local Variables:
%%% mode: latex
%%% TeX-master: "main"
%%% End:


\documentclass[simplex.tex]{subfiles}
% NO NEED TO INPUT PREAMBLES HERE
% packages are inherited; you can compile this on its own
\begin{document}
\subsection{Robust Law of Large Graphs}
%% Jan
To estimate the mean of a collection of weighted graphs under a
low rank random graph model (e.g. Stochastic Blockmodel) when
observing contaminated graphs, we propose an estimator which not
only inherits robustness from element-wise robust estimators but
also has small variance due to application of a rank-reduction
procedure. Under appropriate conditions, we prove that our
estimator outperforms standard estimators via asymptotic relative
efficiency.  Previously we illustrated our theory and methods by Monte
Carlo simulation. And now we focus on the real data experiment.

The real data we consider is a structural connectomic data.
The graphs are based on diffusion tensor MR
images. It contains 114 different brain scans, each of
which was processed to yield an undirected, weighted graph with no
self-loops, using the m2g/ndmg pipelines.  The vertices of the graphs
represent different regions in the brain defined according to an atlas.
We used the  desikan atlas with 70 vertices. The weight of an edge
between two vertices represents the number of white-matter tract
connecting the corresponding two regions of the brain.
As we know, ndmg is a better pipeline compared to m2g, which means that the mean graph derived from ndmg should be a more accurate estimate to actual population mean graph.
In order to evaluate the performance of the four estimators, we build estimates based on the samples from m2g, while using the sample mean graph from ndmg as an estimate of the probability matrix $P$.
Specifically, each Monte Carlo replicate corresponds to sampling $m$ graphs out
of the 114 from the m2g dataset and computing the four estimates based on the $m$ sampled graphs.
We then compared these estimates to the sample mean for the 114 graphs from the ndmg dataset.
We ran 100 simulations for the sample sizes $m=2, 5, 10$.
We also considered all possible dimensions for adjacency spectral embedding by ranging d from 1 to 70 in
order to investigate the impact of the dimension selection procedures.
We plot the result in figure~\ref{fig:robDim}

\begin{figure}[h!]
\begin{cframed}
\centering
\includegraphics[width=\textwidth]{../../figs/CCI_m2g_ndmg_Weighted_q_0.9_EIG.png}
\caption{
{\bf Comparison of MSE of the four estimators for the desikan atlases at three sample sizes based on m2g and ndmg pipelines.}
{\bf 1. MLE (horizontal solid line) vs MLqE (horizontal dotted line):}
ML$q$E outperforms MLE since robust estimators are always preferred in practice;
{\bf 2. MLE (horizontal solid line) vs MLE\_ASE (dashed line):} MLE\_ASE wins the bias-variance tradeoff when embedded into a proper dimension;
{\bf 3. MLqE (horizontal dotted line) vs ML$q$E\_ASE (dashed dotted line):}
ML$q$E\_ASE wins the bias-variance tradeoff when embedded into a proper dimension;
{\bf 4.  ML$q$E\_ASE (dashed dotted line) vs MLE\_ASE (dashed
line):}
MLqE\_ASE is better, since it inherits the robustness from
ML$q$E. And the square and circle represent the dimensions selected by the Zhu and Ghodsi method. We can see it does a pretty good job. But more importantly, a wide range of dimensions could lead to an improvement.
}
\label{fig:robDim}
\end{cframed}
\end{figure}
\clearpage

%% Feb
We had theorems for the ML$q$E under the exponential distribution. Actually the results can be generalized to a broader class of distribution families, and even a different entry-wise robust estimator other than ML$q$E with the following conditions:
\begin{compactenum}
\item Let $A_{ij} \stackrel{ind}{\sim} (1-\epsilon) f_{P_{ij}} + \epsilon f_{C_{ij}}$, then $E[(A_{ij} - E[\hat{P}_{ij}^{(1)}])^k] \le \mathrm{const} \cdot k!$, where $\hat{P}^{(1)}$ is the entry-wise MLE as defined before;
This is to ensure the that observations will not deviate from the expectation too far away, such that the concentration inequality can apply.
\item There exists $C_0(P_{ij}, \epsilon) > 0$ such that under the contaminated model with $C > C_0(P_{ij}, \epsilon)$,
\[
	\lim_{m \to \infty} \left| E[\hat{P}_{ij}] - P_{ij} \right| <
    \lim_{m \to \infty} \left| E[\hat{P}^{(1)}_{ij}] - P_{ij} \right|;
\]\\
It requires the contamination of the model to be large enough (a restriction on the distribution) and $\hat{P}$ to be robust enough with respect to the contamination (a condition on the estimator).
\item $\hat{P}_{ij} \le \mathrm{const} \cdot \hat{P}_{ij}^{(1)}$; (This might be generalized to with high probability later)\\
Since we use the results of $\hat{P}^{(1)}$ to bound $\hat{P}^{(q)}$, the proof can apply directly with this condition for an arbitrary $\hat{P}$.
\item $\mathrm{Var}(\hat{P}_{ij}) = O(m^{-1})$, where $m$ is the number of observations.\\
We will get exactly the same results under this condition. However, even if the variance of the new estimator is not of order $O(m^{-1})$, we will get similar results with a different term related to $m$.
\end{compactenum}

\clearpage

%% March
Although we only present the results under exponential distributions, the results can be generalized to a broader class of distribution families, and even a different entry-wise robust estimator other than ML$q$E with the following conditions:
\begin{compactenum}
\item Let $A_{ij} \stackrel{ind}{\sim} (1-\epsilon) f_{P_{ij}} + \epsilon f_{C_{ij}}$, then $E[(A_{ij} - E[\hat{P}_{ij}^{(1)}])^k] \le \mathrm{const}^k \cdot k!$, where $\hat{P}^{(1)}$ is the entry-wise MLE as defined before;\\
This is to ensure that observations will not deviate from the expectation too far away, so that the concentration inequalities hold.
\item There exists $C_0(P_{ij}, \epsilon) > 0$ such that under the contaminated model with $C > C_0(P_{ij}, \epsilon)$,
\[
	\lim_{m \to \infty} \left| E[\hat{P}_{ij}] - P_{ij} \right| <
    \lim_{m \to \infty} \left| E[\hat{P}^{(1)}_{ij}] - P_{ij} \right|;
\]\\
It requires the contamination of the model to be large enough (a restriction on the distribution) and $\hat{P}$ to be robust enough with respect to the contamination (a condition on the estimator).
\item $\hat{P}_{ij} \le \mathrm{const} \cdot \hat{P}_{ij}^{(1)}$;\\
Since we use the results of $\hat{P}^{(1)}$ to bound $\hat{P}^{(q)}$, the proof can apply directly with this condition for an arbitrary $\hat{P}$.
\item $\mathrm{Var}(\hat{P}_{ij}) = O(m^{-1})$, where $m$ is the number of observations.\\
We will get exactly the same results based on this order. However, even if the variance of the new estimator is not of order $O(m^{-1})$, we will get similar results with a different term related to $m$.
\end{compactenum}

Previously we consider the model to be based on exponential distribution, which is continuous and monotone. Now we consider Poisson distribution instead. Poisson distribution is a commonly used distribution for nonnegative graphs with integer values. And we will prove that it satisfies the conditions for generalization and as a result all theories apply directly.

Let $A_{ij} \stackrel{ind}{\sim} (1-\epsilon) f_{P_{ij}} + \epsilon f_{C_{ij}}$ with $f$ to be Poisson, then we proved that $E[(A_{ij} - E[\hat{P}_{ij}^{(1)}])^k] \le \mathrm{const}^k \cdot k!$, where $\hat{P}^{(1)}$ is the entry-wise MLE as defined before.
So Condition 1 is satisfied. Intuitively, since exponential distribution has a fatter tail compare to Poisson, we should have the bound for central moment of Poisson directly from the results for exponential distribution.
Condition 2 is satisfied as long as the contamination is large enough while keep using the robust ML$q$E.
For Condition 3, the extreme case happens when there are $m$ data $x_1, \cdots, x_m$ with $0 \le x_1 = \cdots = x_k \le \bar{x} \le x_{k+1} = \cdots = x_m \le m \bar{x}/(m - k)$. In order to have ML$q$E larger than MLE $\bar{x}$, we need the weights of the first $m$ data to be smaller than the weights of the rest $m - k$ data. So $e^{-\bar{x}} < \bar{x}^{x_m} e^{-\bar{x}} / x_m!$. Then $x_m! < \bar{x}^{x_m}$. By the lower bound in Stirling's formula, we have $x_m < e \bar{x}$ when $x_m > 0$. Note that if $x_m = 0$ then MLE equals ML$q$E since all data equals zero. Thus ML$q$E is bounded by $e \bar{x}$. As a result, $\hat{P}_{ij} \le e \hat{P}_{ij}^{(1)}$ and Condition 3 is satisfied.
At last, Condition 4 follows directly from theory of minimum contrast estimators.

So for all the theorems proved before, we can replace the exponential distribution by Poisson distribution and all the results still hold.

\clearpage
\end{document}


\subsubsection{Subsystem Overview}
The air-to-ground communication scheme between the platform management board and the base station is responsible for transmitting video, ML results, and control commands. It is a bi-directional, high bandwidth communication channel that requires a stable connection range of up to 30 meters (\textbf{NF.CM.1}).

\subsubsection{Use of Two Communication Links}
There are two options for establishing this air-to-ground communication link - single channel or dual channel.

The first option is to use the existing communication channel to the multirotor (used for drone control), to transmit data. This would be advantageous as it doesn't require additional hardware and saves power. The disadvantage is that the drone control is using an off-the-shelf module, and in order to extend its functionality we would need to make modifications to a highly integrated system.

The second option is to use a separate air-to-ground communication channel. This channel can be established under commonly used wireless communication methods (ex. Wi-Fi or Bluetooth), requiring a dedicated pair of transceivers. The advantage of this option is that most single-board computers are equipped with wireless transceivers and the communication scheme is easily configured. As such, we decided to employ this option.

\subsubsection{Bandwidth Requirements}

The majority of the bandwidth will be reserved for video transmission as it's the most intensive transmission task performed by the computing platform. The total number of bits per second of video that needs to be transmitted can be calculated using the following formula:

$$
\text{\# of bits/second} = \frac{\text{\# of bits}}{\text{1 pixel}} \times \frac{\text{\# of pixels}}{\text{1 frame}} \times \frac{\text{\# of frames}}{\text{1 second}}
$$

The video that will be transmitted, assuming no compression, has a resolution of 640x480 pixels at 30 frames per second. The colour depth is 24-bit for a RGB colour set (that is, each pixel is 8 bits). As such:

$$
\text{\# of bits/second} = \frac{8}{\text{1 pixel}} \times \frac{640\times 480}{\text{1 frame}} \times \frac{30}{\text{1 second}} = 73.738~\text{Mbits/s}
$$

The other data that needs to be transmitted includes the video metadata, the results from ML model, the control commands, and other protocol overheads. Thus, an upper bound for the total bandwidth required by the system is roughly 75 Mbps.

\subsubsection{Communication Scheme}

The communication method we chose for the project is Wi-Fi. The specific standard we chose to utilize is IEEE 802.11n (Wi-Fi 4), as it has enough throughput and nearly all modern devices equipped with Wi-Fi support this standard. (\textbf{C.EX.3})

The advantages of Wi-Fi over other communication methods (such as Bluetooth) are as follows:
\begin{itemize}
    \item Long transmission range. IEEE 802.11n Wi-Fi has a transmission range of up to 53 m. (\textbf{NF.CM.1})
    \item High transmission rate. IEEE 802.11n Wi-Fi has a transmission rate up to 600 Mbps.
    \item No license is required.
    \item After the initial configuration, the connection is capable of auto-establishment. (\textbf{F.CM.3})
\end{itemize}


\section{Network Architecture}%
\label{subsec:l2hmc_network}
As previously mentioned, each of the functions $Q$, $S$, and $T$, are
implemented using multi-layer perceptrons with shared weights.
%
It's important to note that we keep separate the network responsible for
paramterizing the functions used in the position updates (`$\Xnet$', i.e.\
$Q_x$, $S_x$, and $T_x$), and the network responsible for parameterizing the
momentum updates (`$\Vnet$', i.e.\ $Q_v$, $S_v$, and $T_v$).
%
% Since both networks are identical, we describe the architecture of $\Vnet$
% below, and include a flowchart for $\Xnet$ illustrative purposes in
% Fig~\ref{fig:x_net_flowchart}.
%
\begin{figure}[htpb]
  \centering
  \includegraphics[width=\textwidth]{final/net.png}
  \caption{Illustration showing the generic (fully-connected) network
    architecture for training $S_x$, $Q_x$, and $T_x$.}%
    \label{fig:xnet}
\end{figure}

% \begin{figure}[htpb]
%   \centering
%   \input{tikz/vnet}
%   \caption{Illustration showing the generic (fully-connected) network
%     architecture for training $S_v$, $Q_v$, and $T_v$. Figure adapted
%     with permission from~\cite{joeyl2hmc}.}%
% \label{fig:generic_net}
% \end{figure}
%

The network takes as input $\zeta_1 = (x, \partial_{x} U(x), t)$, where $x, v
\in \mathbb{R}^{n}$, and $t$ is encoded as $\tau(t) = \left(\cos{(\frac{2\pi
t}{N_{\mathrm{LF}}})},\right.  \left.\sin{(\frac{2\pi
t}{N_{\mathrm{LF}}})}\right)$.
%
Each of the inputs is then passed through a fully-connected (`dense' layer),
consisting of $n_h$ hidden units
%
\begin{align}
    \tilde x &= W^{(x)} x + b^{(x)} \quad (\in \mathbb{R}^{n_h})\\
    \tilde v &= W^{(v)} v + b^{(v)} \quad (\in \mathbb{R}^{n_h})\\
    \tilde \tau &= W^{(\tau)} \tau + b^{(\tau)} \quad (\in \mathbb{R}^{n_h}).
\end{align}
%
Where $W^{(x)}, W^{(v)} \in \mathbb{R}^{n \times n_h}$, $W^{(t)} \in
\mathbb{R}^{2 \times n_h}$, and $b^{(x)}$, $b^{(v)}$,  $b^{(t)} \in
\mathbb{R}^{n_h}$.
%
From these, the network computes
%
\begin{equation}
    h_1 = \sigma(\tilde x + \tilde v + \tilde \tau) \quad (\in
    \mathbb{R}^{n_h}).
    \label{eq:hidden_1}
\end{equation}
%
Where $\sigma(x) = \max(0, x)$ denotes the rectified linear unit (ReLU)
activation function.
%
Next, the network computes
%
\begin{equation}
    h_2 = \sigma\left(W^{(h_1)} h_1 + b^{(h_1)}\right) \quad (\in
    \mathbb{R}^{n_h}).
    \label{eq:hidden_2}
\end{equation}
%
These weights ($h_2$) are then used to compute the network's output:
%
\begin{align}
    S_x &= \lambda_S \tanh(W^{(S)} h_2 + b^{(S)})\quad (\in \mathbb{R}^{n})\\
    Q_x &= \lambda_{Q} \tanh(W^{(Q)} h_2 + b^{(Q)})\quad (\in \mathbb{R}^{n})\\
    T_x &= W^{(T)} h_2 + b^{(T)}\quad (\in \mathbb{R}^{n}),
\end{align}
%
Where $W^{(s)}, W^{(q)}$, and $W^{(T)} \in \mathbb{R}^{n_h \times n}$ and
$b^{(s)}, b^{(q)}$, and $b^{(T)} \in \mathbb{R}^{n}$.
%
The parameters $\lambda_s$ and $\lambda_q$ are additional trainable variables
initialized to zero.
%
The network used for parameterizing the functions $T_v$, $Q_v$ and $S_v$ takes
as input $(x, \partial_x U(x), t)$ where again $t$ is encoded as above.  The
architecture of this network is the same, and produces outputs $T_v$, $Q_v$,
and $S_v$.

% \begin{figure}[htpb]
%   \centering
%   % \includegraphics[width=\textwidth]{generic_net/x_net_flowchart4.png}
%   % \input{tikz/vnet.tex}
%   \caption{Flowchart illustrating the generic fully-connected network
%     architecture including the intermediate variables computed at each hidden
%     layer of the network.}%
% \label{fig:x_net_flowchart}
% \end{figure}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%