\iffullversion
\else

\ifccs
\section{Non-unique Join on Column}\label{sec:nonunique}
When both tables contain duplicates we fall back to a less secure protocol architecture. This is required due to the cuckoo table not supporting duplicates. First, \Party{1} samples two random permutations $\pi_0,\pi_1$ and computes $X'=\pi_1(X),Y'=\pi_2(Y)$ using the oblivious permutation protocol. \Party{0} then learns all of the randomized encodings for the permuted tables $X'$ and $Y'$. Given this, \Party{0} can compute the size of the output table and inform the other two parties of it. Alternatively, an upper bound on the output table size can be communicated. Let $n'$ denote this value. \Party{0} can then construct two switching networks which map the rows of $X'$ and $Y'$ to the appropriate rows of the output table. The main disadvantage of this approach is that \Party{0} learns the size of the output, the distribution of duplicate rows and how these duplicate rows are multiplied together. However, unlike \cite{LTW13} which takes a conceptually similar approach, our protocol does not leak any information to \Party{1} and \Party{2}, besides the value $n'$.
\fi

%\section{Summary of CCS 2020 Revision}
%
%We have made significant efforts to address \emph{all} concerns that have been raised by the reviewers. The most significant changes include:
%\begin{enumerate}
%	\item Improvements in writing quality. We have rewritten/expanded certain sections which we believe lead to some confusion. The two most notable of these is the introduction and the oblivious switching network sections. The introduction now highlights the "outsourced secure computation setting" where the three parties act as servers that are oblivious to the data that they are computing on. We also give real-world motivations/examples for the setting.
%
%	\item A common comment was that the Duplication network section is confusing. As such, we have largely rewritten this section. The duplication network now has its own protocol box ($\proto{dup}$ of \figureref{fig:switching-net}) as opposed to being inlined into the switch net protocol. We also now start the explanation with a concrete example of the duplication protocol which is indented to give better intuition. This is followed by a new explanation of the "warmup" along with how to generalize it. A security proof of the protocol has been added to the appendix.
%	%	x  warmup was not clear.
%	%	x  Clearly state how to generalize (required!)
%	%	x  missing proof of correctness/security (required!)
%
%	\item The switching network section now starts with a concrete example that should aid understanding. We have also reworked the explanation in the text to be easier to read. Finally, we also give a comparison with two party computation switching network and permutation network based on Oblivious Transfer and Homomorphic Encryption.
%
%	\item Some reviewers were confused by the fact that the oblivious permutation is actually an oblivious injection. We made this distinction clearer.
%
%	\item We have added a discussion on microbenchmarks to the experiment section 6. This describes the relative amount of time each step takes.
%
%
%	\item We now more clearly compare with Google's Join-and-Compute protocol. This protocol was actually already compared with but we did not make it clear that it is the protocol that Google uses. We note that this protocol is significantly slower than ours and is not composable. We are not aware of any two party protocol that has an implementation and is composable.
%
%	\item We added formal proofs of security for the core protocols (permutation, duplication, switch net, join protocol). These are in the appendix.
%
%	\item
%	One of the reviewers suggested we compared with VaultDB. We appreciate the suggestion and have cited the work but decided not to compare due to their protocol targeting a significantly different setting. Mapping our protocol into their setting would be an interesting future direction.
%
%	\item The ideal functionality and protocol boxes for the Join protocol have been reworked to improve readability.
%\end{enumerate}
%
%Some other minor changes include:
%\begin{enumerate}
%\item  We clearly state of cuckoo hash table $m\approx1.5n$.
%\item  We note that we are open source.
%\item  Fixed various typos.
%\item  Include page numbers.
%\item  Clearly state that KKRT can not be made composable without very large overhead.
%\end{enumerate}

\section{Voter Query Details}\label{sec:voterDetails}

\begin{figure*}[t!]\centering\footnotesize
	% \begin{figure*}[h]\centering
	\begin{tabular}{|l|| r | r |r |r|r|r||r|r | r |r |r|r|}
		\cline{2-13}
		\multicolumn{1}{c}{}         & \multicolumn{6}{|c||}{LAN}                                   & \multicolumn{6}{|c|}{WAN}                                    \\ \hline
		\multirow{2}{*}{Application} &                  \multicolumn{6}{c||}{$n$}                   &                   \multicolumn{6}{c|}{$n$}                   \\
		& $2^8$ & $2^{12}$ & $2^{16}$ & $2^{20}$ & $2^{24}$ & $2^{26}$ & $2^8$ & $2^{12}$ & $2^{16}$ & $2^{20}$ & $2^{24}$ & $2^{26}$ \\ \hline\hline
		Voter Intra-state            & 0.01  & 0.02     & 0.2      & 4.7      &    114.7 &  2,190.1 &   1.0 &      1.0 & 2.2      & 27.1     & 456.1    &  7,463.9 \\ \hline
		Voter Inter-state            & 0.01  & 0.02     & 0.3      & 7.0      &    134.8 &  2,546.4 &   1.6 &      1.6 & 4.0      & 45.4     & 747.7    & 12,284.1 \\ \hline
		Threat Log $N=2$          & 0.02  & 0.03     & 0.2      & 5.1      &    121.4 &    488.1 &   2.4 &      2.5 & 4.8      & 34.6     & 585.6    &  2,342.4 \\ \hline
		Threat Log $N=4$           & 0.05  & 0.09     & 0.9      & 17.9     &    388.4 &  1,553.9 &   6.6 &      6.8 & 13.1     & 108.7    & 1,739.2  &  6,956.8 \\ \hline
		Threat Log $N=8$          & 0.10  & 0.19     & 1.7      & 47.1     &  1,021.0 & 16,336.1 &  14.9 &     15.3 & 30.0     & 264.3    & 4,228.8  & 16,915.2 \\ \hline
	\end{tabular}
\vspace{-0.3cm}
	\caption{\label{fig:app} The running time in seconds for the Voter Registration and Threat Log applications. The input tables each contain $n$ rows.  }
	\vspace{-0.3cm}
\end{figure*}

Given the problem statement from \ref{sec:voter}, a naive solution is to construct a centralized database of all the registered voters and citizen records. It is then a relatively straightforward process to identify persons with inaccurate records, attempt to double register or are simply not register at all. However, the construction of such a centralized repository of information has long had strong opposition in the United States due to concerns of data privacy and  excessive government overreach. As a compromise many states have volunteered to join the Electronic Registration Information Center (ERIC)\cite{eric} which is a non-profit organization with the mission of assisting states to improve the accuracy of America’s voter rolls and increase access to voter registration for all eligible citizens. This organization acts as a semi-trusted third party which maintains a centralized database containing hashes of the relevant information, e.g. names, addresses, drivers license number and social security number.
\fi

In particular, instead of storing this sensitive information in plaintext, all records are randomized using two cryptographically strong salted hash functions. Roughly speaking, before this sensitive information is sent to ERIC, each state is provided with the first salt value $salt_1$ and updates each value $v$ as $v := H(salt_1 || v)$. This hashed data is then sent to ERIC where the data is hashed a second time by ERIC which possesses the other salt value. The desired comparisons can then be applied to the hashed data inside ERIC's secure data center. When compared with existing alternative, this approach provides a moderate degree of protection. In particular, so long as the salt values remain inaccessible by the adversary, deanatomized any given record is likely non-trivial. However, a long series of works, e.g. \cite{deanon0,deanon1,deanon2,deanon3,deanon4}, have shown that a significant amount of information can be extracted with sophisticated statistical techniques. Moreover, should the adversary possess the salt values a straightforward dictionary attack can be applied.

We propose adding another layer of security with the deployment of our secure database join framework. In particular, two or more of the states and ERIC will participate in the MPC protocol. From here we consider two possible solutions. The first option is to maintain the existing repository but now have it secret shared between the computational parties. Alternatively, each state could be the long-term holder of their own data and the states perform all pairwise comparison amongst themselves. For reason of preferring the more distributed setting we further explore the pairwise comparison approach.

The situation is further complicated by how this data is distributed within and between states. In the typical setting no single state organization has sufficient information to identify individuals which are incorrectly or double registered. For example, typical voter registration forms requires a name, home address and state ID/driver's license number. If two states compared this information there would be no reliable attribute for joining the two records. The name of the voter could be used but names are far from a unique identifier. The solution taken by ERIC is to first perform a join between a state's registered voters and their Department of Motor Vehicles (DMV) records, using the  state ID/driver's license number as the join-key. Since the DMV typically possesses an individual's Social Security Number (SSN), this can now be used as a unique identifier across all states. However, due to regulations within some states this join is only allowed to be performed on the hashed data or, presumably, on secret shared data.

In addition to identifying individuals that are double registered, the mission of ERIC is to generally improve the accuracy of all voter records. This includes identifying individuals that have moved and not yet registered in their new state or that have simply moved within a state and not updated their current address. In this case the joins between/within states should also include an indicator denoting that an individual has updated their address at a DMV which is different than the voter registration record. There are likely other scenarios which ERIC also identifies but we leave the exploration of them to future work.

Given the building blocks of \sectionref{sec:construction} it is a relatively straightforward task to perform the required joins. First a state performs a left join between their DMV data and the voter registration data. Within this join the addresses in the inner join are compared. In the event of a discrepancy, the date of when these addresses were obtained can be compared to identify the most up to date address. Moreover, the agency with the older address can be notified and initial a procedure to determine which, if any, of the addresses should be updated.

Once this join is performed, each state holds a secret shared table of all their citizens that possess a state ID and their current registration status. Each pair of states can then run an inner join protocol using the social security number as the key. There are several cases that a result record can be in. First it is possible for a person to have a DMV record in two states and be registered in neither. The identity of these persons should not be revealed as this does not effect the voting process. The next case is that a person is registered in both states. We wish to reveal this group to both states so that the appropriate action can be taken. The final case that we are interested in is when a person is registered in state \emph{A} and has a newer DMV address in state \emph{B}. In this case we want to reveal the identity of the person to the state that they are registered to. This state can then contact the person to inquire whether they wish to switch their registration to the new state.

This approach has additional advantages over the hashing technique of ERIC. First, all of the highly sensitive information such as a persons address, state ID number and SSN can still be hashed before being added to the database\footnote{The hashing originally performed by ERIC can be replaced with the randomized encoding protocol.}. However, now that the data is secret shared less sensitive information such as dates need not be hashed. This allows for the more expressive query described above which uses a numerical comparison. To achieve the the same functionality using the current ERIC approach these dates would have to be stored in plaintext which leaks significant information. In addition, when the ERIC approach performs these comparison the truth value for each party of the predicate is revealed. Our approach reveals no information about any intermediate value.

\begin{figure}[ht]

	{
		\scriptsize
		\begin{align*}
		stateA = \texttt{select }& DMV.name,\\
		& DMV.ID, \\
		& DMV.SSN, \\
		& DVM.date > Voter.date \ ?\\
		&\quad DMV.date : Voter.date \texttt{ as } date,\\
		& DVM.date > Voter.date \ ?\\
		&\quad  DMV.address : Voter.address \texttt{ as } address,\\
		& DVM.address \neq Voter.address \texttt{ as } mixedAddress, \\
		& Voter.name \neq \texttt{ NULL as } registered \\
		\texttt{ from } & DMV \texttt{ left join } Voter \\
		\texttt{ on } & DMV.ID = Voter.ID \\
		stateB = \texttt{select }&...\\
		resultA = \texttt{select } & stateA.SSN \\
		& stateA.address \texttt{ as } addressA\\
		& stateB.address \texttt{ as } addressB\\
		& stateA.registered \\
		& stateB.registered \\
		\texttt{ from } & stateA \texttt{ inner join } stateB \\
		\texttt{ on } & stateA.SSN = stateB.SSN\\
		\texttt{ where } & (stateA.date < stateB.date \texttt{ and } stateA.registered ) \\
		\texttt{ or } & (stateA.registered \qquad \qquad \ \, \texttt{ and }stateB.registered )\\
		resultB = \texttt{select } & ...
		\end{align*}
	}
	\caption{SQL styled join query for the ERIC voter registration application. \label{fig:voterQuery}}
\end{figure}

Once the parties construct the tables in \figureref{fig:voterQuery}, state \emph{A} can query the table $stateA$ to reveal all IDs and addresses where the $mixedAddress$ attribute is set to \texttt{true}. This reveals exactly the people who have conflicting addresses between that state's voter and DMV databases. When comparing voter registration data between states, state B should define $stateB$ in a symmetric manner as $stateA$. The table $resultA$ contains all of the records which are revealed to state \emph{A} and $resultB$, which is symmetrically defined, contains the results for state \emph{B}. We note that $resultA$ and $resultB$ can be constructed with only one join.

Both types of these queries can easily be performed in our secure framework. All of the conditional logic for the select and where clauses are implemented using a binary circuit immediately after the primary join protocol is performed. This has the effect that overhead of these operation is simply the size of the circuit which implements the logic times the number of potential rows contained in the output.


%-------------------------------------------------------------------------------
\section{String signal morphing/shape studies}
\label{sec:StrMorphShapeStudies}
%%\addtocontents{toc}{\protect\setcounter{tocdepth}{0}}

This appendix focusses on the shape studies performed with the string signal MC samples. The morphing part is also discussed.

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

\subsection{Signal morphing}
\label{subsec:StrMorphShapeStudies:SigMorph}
Due to the availability of limited computing resources as well as time crunch, MC signal shapes can be generated for a limited number of masses only. In case there is a need for more MC signal shapes, it's worth using the interpolation between the already generated signal shapes to obtain various intermediate signal shapes. This procedure is called signal morphing. First, the generated MC signal shapes are fit successfully using suitable functions. Following the fits, all the fit parameters become functions of mass. Then, the corresponding fit parameters from different signal shapes are fit with the cubic splines. Afterwards, applying the interpolation technique, the intermediate  signal shapes are created by evaluating the spline fits at the desired mass points.

~~~~~~~~ Five string signal MC samples have been generated for the dijet q/g tagged analysis. One could use the splines from the fits of these samples, but there seems to be no need for further signal morphing as the generated samples sufficiently cater to the requirement.

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

\subsection{Initial shape studies}
\label{subsec:StrMorphShapeStudies:InitShapStud}

The usual Gaussian+reverse-Landau (GrL) function does a fairly good job of fitting a wide variety of MC signals used in the high mass dijet searches. They work well for excited quark ($q^{*}$ ), $W$ and $Z$ signals. On the other hand, the string signals are a bit unusual in nature -- their mass does not peak around the mass scale ($M_{s}$) used during the generation. The motivation for string signal shape studies comes from this very unusual nature of the samples.

~~~~~~~ The very first string signal shape studies had been carried out during the initial days of the analysis, when the selection cuts were not finalized. Therefore, the $m_{jj}$ distributions did not have any cuts applied to them and they also had a uniform bin-width of 100 GeV (Figure \ref{fig:InitStrmjj}).

\begin{figure}[!htb]
  \centering
  \subfigure[$M_{s} = 7.0$ TeV.]{
  \includegraphics[width=0.45\textwidth]{figures/app-StrMorphShapeStudies/mjj_Old_string_ntuples_7TeV.png} }
  \subfigure[$M_{s} = 7.5$ TeV.]{
  \includegraphics[width=0.45\textwidth]{figures/app-StrMorphShapeStudies/mjj_Old_string_ntuples_7p5TeV.png} }
  \subfigure[$M_{s} = 8.0$ TeV.]{
  \includegraphics[width=0.45\textwidth]{figures/app-StrMorphShapeStudies/mjj_Old_string_ntuples_8TeV.png} }
  \subfigure[$M_{s} = 8.5$ TeV.]{
  \includegraphics[width=0.45\textwidth]{figures/app-StrMorphShapeStudies/mjj_Old_string_ntuples_8p5TeV.png} }
  \subfigure[$M_{s} = 9.0$ TeV.]{
  \includegraphics[width=0.45\textwidth]{figures/app-StrMorphShapeStudies/mjj_Old_string_ntuples_9TeV.png} }
  \caption{The string signal $m_{jj}$ shapes from the corresponding MC samples.}
  \label{fig:InitStrmjj}
\end{figure}

The list of functions that were considered to fit the $m_{jj}$ shapes are given below:

\begin{itemize}
    \item Crystal-Ball function (CB)
    \item Reverse-Landau (rL)
    \item Comibation of a Gaussian and a reverse-Landau (GrL)
    \item Convolution between a Gaussian and an exponential (GcE) $\rightarrow$ best results
    \item Combination of Planck and a Gaussian (PG)
\end{itemize}

The GcE is of the form

\begin{equation}
a~e^{-c~(-(x-b)-\frac{d^{2}c}{2})}[1+\mathrm{erf}(\frac{-(x-b)-d^{2}c}{d\sqrt{2}})]
\end{equation}

~ with $a$ -- amplitude, $b$ -- Gaussian mean (offset), $c$ -- lambda of exponential and $d$ -- Gaussian width (sigma).

~~~~~~ The expression for GrL (the conventional one) is

\begin{equation}
a ~[b ~ \mathrm{exp}(d(x-c)-e^{d(x-c)}) + (1-b) ~ \mathrm{exp}(-0.5 ~ (\frac{x-e}{f})^{2})]
\end{equation}

~~ where $a$ -- relative normalization, $b$ -- fraction of reverse-Landau/Gaussian components, $c$ -- reverse-Landau mean (offset), $d$ -- reverse-Landau width (scale), $e$ -- Gaussian mean (offset), and $f$ -- Gaussian width (sigma).

\clearpage

The fits from GcE and GrL (the conventional one) are shown in Figures \ref{fig:InitGcEGrL-1} and \ref{fig:InitGcEGrL-2} for all string signal MC samples.

\begin{figure}[!htb]
  \centering
  \subfigure[$M_{s} = 7.0$ TeV w/ GcE.]{
  \includegraphics[width=0.45\textwidth]{figures/app-StrMorphShapeStudies/GcEFit_Old_ntuples_7TeV.png} }
  \subfigure[$M_{s} = 7.0$ TeV w/ GrL.]{
  \includegraphics[width=0.45\textwidth]{figures/app-StrMorphShapeStudies/GrLFit_Old_ntuples_7TeV.png} }
  \subfigure[$M_{s} = 7.5$ TeV w/ GcE.]{
  \includegraphics[width=0.45\textwidth]{figures/app-StrMorphShapeStudies/GcEFit_Old_ntuples_7p5TeV.png} }
  \subfigure[$M_{s} = 7.5$ TeV w/ GrL.]{
  \includegraphics[width=0.45\textwidth]{figures/app-StrMorphShapeStudies/GrLFit_Old_ntuples_7p5TeV.png} }
  \subfigure[$M_{s} = 8.0$ TeV w/ GcE.]{
  \includegraphics[width=0.45\textwidth]{figures/app-StrMorphShapeStudies/GcEFit_Old_ntuples_8TeV.png} }
  \subfigure[$M_{s} = 8.0$ TeV w/ GrL.]{
  \includegraphics[width=0.45\textwidth]{figures/app-StrMorphShapeStudies/GrLFit_Old_ntuples_8TeV.png} }
  \caption{The GcE and GrL fits on the string signal shapes for $M_{s} = 7.0,~7.5$ and $8.0$ TeV.}
  \label{fig:InitGcEGrL-1}
\end{figure}

\begin{figure}[!htb]
  \centering
  \subfigure[$M_{s} = 8.5$ TeV w/ GcE.]{
  \includegraphics[width=0.45\textwidth]{figures/app-StrMorphShapeStudies/GcEFit_Old_ntuples_8p5TeV.png} }
  \subfigure[$M_{s} = 8.5$ TeV w/ GrL.]{
  \includegraphics[width=0.45\textwidth]{figures/app-StrMorphShapeStudies/GrLFit_Old_ntuples_8p5TeV.png} }
  \subfigure[$M_{s} = 9.0$ TeV w/ GcE.]{
  \includegraphics[width=0.45\textwidth]{figures/app-StrMorphShapeStudies/GcEFit_Old_ntuples_9TeV.png} }
  \subfigure[$M_{s} = 9.0$ TeV w/ GrL.]{
  \includegraphics[width=0.45\textwidth]{figures/app-StrMorphShapeStudies/GrLFit_Old_ntuples_9TeV.png} }
  \caption{The GcE and GrL fits on the string signal shapes for $M_{s} = 8.5$ and $9.0$ TeV.}
  \label{fig:InitGcEGrL-2}
\end{figure}

\clearpage

In order to have a better idea about the behaviour of the resultant fit parameters, they have been fitted with linear functions. Figures \ref{fig:InitGcEParam} and \ref{fig:InitGrLParam} contain the parameter-fits from the GcE and GrL fits respectively.

\begin{figure}[!htb]
  \centering
  \subfigure[GcE: $a$ -- amplitude.]{
  \includegraphics[width=0.45\textwidth]{figures/app-StrMorphShapeStudies/GcEFitParam_a_Old_ntuples.png} }
  \subfigure[GcE: $b$ -- Gaussian mean (offset).]{
  \includegraphics[width=0.45\textwidth]{figures/app-StrMorphShapeStudies/GcEFitParam_b_Old_ntuples.png} }
  \subfigure[GcE: $c$ -- lambda of exponential.]{
  \includegraphics[width=0.45\textwidth]{figures/app-StrMorphShapeStudies/GcEFitParam_c_Old_ntuples.png} }
  \subfigure[GcE: $d$ -- Gaussian width (sigma).]{
  \includegraphics[width=0.45\textwidth]{figures/app-StrMorphShapeStudies/GcEFitParam_d_Old_ntuples.png} }
  \caption{The linearly fitted GcE fit parameters for $M_{s} = 7.0,~7.5,~8.0,~8.5$ and $9.0$ TeV.}
  \label{fig:InitGcEParam}
\end{figure}

\clearpage

\begin{figure}[!htb]
  \centering
  \subfigure[GrL: $a$ -- relative normalization.]{
  \includegraphics[width=0.45\textwidth]{figures/app-StrMorphShapeStudies/GrLFitParam_a_Old_ntuples.png} }
  \subfigure[GrL: $b$ -- fraction of reverse-Landau/Gaussian components.]{
  \includegraphics[width=0.45\textwidth]{figures/app-StrMorphShapeStudies/GrLFitParam_b_Old_ntuples.png} }
  \subfigure[GrL: $c$ -- reverse-Landau mean (offset).]{
  \includegraphics[width=0.45\textwidth]{figures/app-StrMorphShapeStudies/GrLFitParam_c_Old_ntuples.png} }
  \subfigure[GrL: $d$ -- reverse-Landau width (scale).]{
  \includegraphics[width=0.45\textwidth]{figures/app-StrMorphShapeStudies/GrLFitParam_d_Old_ntuples.png} }
  \subfigure[GrL: $e$ -- Gaussian mean (offset).]{
  \includegraphics[width=0.45\textwidth]{figures/app-StrMorphShapeStudies/GrLFitParam_e_Old_ntuples.png} }
  \subfigure[GrL: $f$ -- Gaussian width (sigma).]{
  \includegraphics[width=0.45\textwidth]{figures/app-StrMorphShapeStudies/GrLFitParam_f_Old_ntuples.png} }
  \caption{The linearly fitted GrL fit parameters for $M_{s} = 7.0,~7.5,~8.0,~8.5$ and $9.0$ TeV.}
  \label{fig:InitGrLParam}
\end{figure}

The Figures \ref{fig:InitGcEGrL-1} and \ref{fig:InitGcEGrL-2} show that the individual GcE fits have better quality (the $\chi^2/\mathrm{ndf}$ values) than the corresponding GrL ones. On top of it, the linear behaviour of the fit parameters is also there for almost all the parameters (via Figures \ref{fig:InitGcEParam} and \ref{fig:InitGrLParam}) for GcE in comparison to GrL. From these two points, it could be concluded that GcE fits the string signal shape better than the conventional GrL.

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

\subsection{Recent shape studies}
\label{subsec:StrMorphShapeStudies:ReceShapStud}
The findings from \ref{subsec:StrMorphShapeStudies:InitShapStud} are reused after the finalization of the selection cuts for the inclusive string analysis. The $m_{jj}$ string signal distributions are produced with $|\Delta\phi_{jj}|>1.0$, $|y^*|<0.8$ and $m_{jj}>1200$ GeV. Also, instead of the uniform $m_{jj}$ binning of 100 GeV, variable bin sizes with the following lower and upper limits are used -- \\

946, 976, 1006, 1037, 1068, 1100, 1133, 1166, 1200, 1234, 1269, 1305, 1341, 1378, 1416, 1454, 1493, 1533, 1573,1614, 1656, 1698, 1741, 1785, 1830, 1875, 1921, 1968, 2016, 2065, 2114, 2164, 2215, 2267, 2320, 2374, 2429, 2485, 2542, 2600, 2659, 2719, 2780, 2842, 2905, 2969, 3034, 3100, 3167, 3235, 3305, 3376, 3448, 3521, 3596, 3672, 3749, 3827, 3907, 3988, 4070, 4154, 4239, 4326, 4414, 4504, 4595, 4688, 4782, 4878, 4975, 5074, 5175, 5277, 5381, 5487, 5595, 5705, 5817, 5931, 6047, 6165, 6285, 6407, 6531, 6658, 6787, 6918, 7052, 7188, 7326, 7467, 7610, 7756, 7904, 8055, 8208, 8364, 8523, 8685, 8850, 9019, 9191, 9366, 9544, 9726, 9911, 10100, 10292, 10488, 10688, 10892, 11100, 11312, 11528, 11748, 11972, 12200, 12432, 12669, 12910, 13156 GeV.

~~~~~ Figure \ref{fig:ReceStrmjj} consists of the string signal shapes with selection cuts and binning described above. All these shapes are fitted with GcE, and after successful fits, the corresponding fit parameters are fitted using the cubic splines. As mentioned in the beginning, these cubic splines could be used for producing intermediate string signal shapes if needed. The GcE fits and the cubic splines are placed at Figures \ref{fig:ReceGcE} and \ref{fig:ReceGcEParam} respectively.

\clearpage

\begin{figure}[!htb]
  \centering
  \subfigure[$M_{s} = 7.0$ TeV.]{
  \includegraphics[width=0.45\textwidth]{figures/app-StrMorphShapeStudies/mjj_New_string_ntuples_7TeV.png} }
  \subfigure[$M_{s} = 7.5$ TeV.]{
  \includegraphics[width=0.45\textwidth]{figures/app-StrMorphShapeStudies/mjj_New_string_ntuples_7p5TeV.png} }
  \subfigure[$M_{s} = 8.0$ TeV.]{
  \includegraphics[width=0.45\textwidth]{figures/app-StrMorphShapeStudies/mjj_New_string_ntuples_8TeV.png} }
  \subfigure[$M_{s} = 8.5$ TeV.]{
  \includegraphics[width=0.45\textwidth]{figures/app-StrMorphShapeStudies/mjj_New_string_ntuples_8p5TeV.png} }
  \subfigure[$M_{s} = 9.0$ TeV.]{
  \includegraphics[width=0.45\textwidth]{figures/app-StrMorphShapeStudies/mjj_New_string_ntuples_9TeV.png} }
  \caption{The string signal $m_{jj}$ shapes from the corresponding MC samples with the selection cuts and variable binning.}
  \label{fig:ReceStrmjj}
\end{figure}

\clearpage

\begin{figure}[!htb]
  \centering
  \subfigure[GcE fit on $M_{s} = 7.0$ TeV (w/ selection cuts and variable binning).]{
  \includegraphics[width=0.45\textwidth]{figures/app-StrMorphShapeStudies/GcEFit_New_ntuples_7TeV.png} }
  \subfigure[GcE fit on $M_{s} = 7.5$ TeV (w/ selection cuts and variable binning).]{
  \includegraphics[width=0.45\textwidth]{figures/app-StrMorphShapeStudies/GcEFit_New_ntuples_7p5TeV.png} }
  \subfigure[GcE fit on $M_{s} = 8.0$ TeV (w/ selection cuts and variable binning).]{
  \includegraphics[width=0.45\textwidth]{figures/app-StrMorphShapeStudies/GcEFit_New_ntuples_8TeV.png} }
  \subfigure[GcE fit on $M_{s} = 8.5$ TeV (w/ selection cuts and variable binning).]{
  \includegraphics[width=0.45\textwidth]{figures/app-StrMorphShapeStudies/GcEFit_New_ntuples_8p5TeV.png} }
  \subfigure[GcE fit on $M_{s} = 9.0$ TeV (w/ selection cuts and variable binning).]{
  \includegraphics[width=0.45\textwidth]{figures/app-StrMorphShapeStudies/GcEFit_New_ntuples_9TeV.png} }
  \caption{GcE fits for string signal shapes after cuts and variable binning.}
  \label{fig:ReceGcE}
\end{figure}

\clearpage

\begin{figure}[!htb]
  \centering
  \subfigure[GcE: $a$ -- amplitude.]{
  \includegraphics[width=0.45\textwidth]{figures/app-StrMorphShapeStudies/GcEFitParam_a_New_ntuples.png} }
  \subfigure[GcE: $b$ -- Gaussian mean (offset).]{
  \includegraphics[width=0.45\textwidth]{figures/app-StrMorphShapeStudies/GcEFitParam_b_New_ntuples.png} }
  \subfigure[GcE: $c$ -- lambda of exponential.]{
  \includegraphics[width=0.45\textwidth]{figures/app-StrMorphShapeStudies/GcEFitParam_c_New_ntuples.png} }
  \subfigure[GcE: $d$ -- Gaussian width (sigma).]{
  \includegraphics[width=0.45\textwidth]{figures/app-StrMorphShapeStudies/GcEFitParam_d_New_ntuples.png} }
  \caption{The cubic splines of GcE fit parameters for $M_{s} = 7.0,~7.5,~8.0,~8.5$ and $9.0$ TeV (after selection cuts and variable binning).}
  \label{fig:ReceGcEParam}
\end{figure}

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

\subsection{Summary}
\label{subsec:StrMorphShapeStudies:Summary}
The shape studies of the string signal MC samples with various fit functions lead to the conclusion that the convolution between a Gaussian and an exponential (GcE) is the best suited template for them.

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


\documentclass[a4paper,12pt]{article}

\usepackage{graphicx}
\usepackage{anysize}
\usepackage{multicol}
% USE setspace BEFORE hyperref (for footnote link)
\usepackage{setspace}
\usepackage{hyperref}
\usepackage{spverbatim}
\usepackage{enumitem}
\usepackage[top=0.5in, left=0.75in, bottom=0.5in, right=0.5in, includefoot]{geometry}
\usepackage{subcaption}
\usepackage[justification=centering]{caption}

\usepackage[compact]{titlesec}
% syntax \titlespacing{<command>}{<left>}{<before>}{<after>}
\titlespacing{\section}{0pt}{-0.5in}{*0}
\titleformat{\section}{\normalfont\fontsize{14}{22}\bfseries}{\thesection}{1em}{}

\setlength{\columnsep}{0.5cm}
\setlength{\parindent}{0pt}

\linespread{1.5}

\begin{document}

  % titlepage
  \input{cg_lab_4_report_title_page}

  \fontsize{14}{22}{\textbf{\underline{LAB 4}}}

  \begin{spacing}{1}
    \hfill \break
    Implement Convex Hull using
    \begin{enumerate}[leftmargin=*]
      \itemsep0em
      \item extreme points
      \item extreme edges
      \item gift wrap
      % \hfill \break
    \end{enumerate}
  \end{spacing}

  \section*{\textbf{\underline{Code}}\footnote{\url{https://github.com/Brihat9/CG/blob/master/cg_lab_4_convex_hull.py}}}

  \begin{spacing}{1}
    \begin{footnotesize}
      \begin{spverbatim}
#!/usr/bin/env python

from basics import Point, LineSegment
from circular_doubly_linked_list import CircularDoublyLinkedList
from cg_lab_3 import is_point_inclusion
from cg_lab_2_lr_turn import is_left_turn, is_colinear, compute_area

import copy
import math
import pprint

''' change input file here '''
INPUT_FILE = 'cg_lab_4_input_file_test'

def get_extreme_points_based_convex_hull(points):
    ''' returns sorted list of extreme points from given set of points
        that forms the convex hull

        parameter: points - list of points

        returns: sorted list of extreme points
    '''
    n = len(points)

    # list to add non extreme points
    non_extreme_points = []

    '''
        for i upto N - 1:
            for j != i upto N -2:
                for k != i != j upto N - 3:
                    for l != i != j != k upto N - 4:
                        if point P_l lies inside triangle(P_i, P_j, P_k):
                            P_l is non-extreme points
    '''
    for i in range(n - 1):
        for j in range(n - 2):
            if j != i:
                for k in range(n - 3):
                    if k != i and k != j:
                        for l in range(n - 4):
                            if l != i and l != j and l != k:
                                # create triangle (polygon)
                                polygon = CircularDoublyLinkedList()
                                polygon.append(points[i])
                                polygon.append(points[j])
                                polygon.append(points[k])

                                # check point_l lies inside triangle (polygon)
                                res = is_point_inclusion(polygon, points[l])

                                # if point lies inside, it is non extreme point
                                if res:
                                    non_extreme_points.append(points[l])

    ''' for testing: displays content of non_extreme_points '''
    # for index in range(len(non_extreme_points)):
    #     print(non_extreme_points[index]),
    #     print("\t"),

    ''' using python 'set' datatype to find extreme point '''
    points_set = set(points)
    non_extreme_points_set = set(non_extreme_points)
    extreme_points_set = points_set - non_extreme_points_set
    extreme_points = list(extreme_points_set)
    # print(extreme_points)

    ''' for sorting extreme points '''
    # calculate centroid of polygon
    centroid = Point(sum([point.x for point in extreme_points])/len(extreme_points),sum([point.y for point in extreme_points])/len(extreme_points))
    # print("Centroid of all Points: " + str(centroid))

    # sort vertices of polygon in anti-clockwise order
    sorted_extreme_points = copy.deepcopy(extreme_points)
    sorted_extreme_points.sort(key=lambda p: math.atan2(p.y-centroid.y,p.x-centroid.x))

    ''' for testing: show points in sorted order '''
    # print("\nExtreme points in sorted order")
    # for index in range(len(extreme_points)):
    #     print(sorted_extreme_points[index]),
    # print("\n")

    return sorted_extreme_points

def get_extreme_edges_based_convex_hull(points):
    ''' returns sorted list of extreme edges from given set of points
        that forms the convex hull

        parameter: points - list of points

        returns: sorted list of extreme edges
    '''
    n = len(points)

    # list to add non extreme points
    extreme_edges = []

    '''
        for i upto N - 1:
            for j != i upto N -2:
                for k != i != j upto N - 3:
                    if point P_k is left or colinear with line(P_i, P_j):
                         line(P_i, P_j) is extreme edge
                     else:
                         line(P_i, P_j) is non-extreme edge
    '''
    for i in range(n):
        for j in range(n):
            if j != i:
                res = [None] * n
                line = LineSegment(points[i], points[j])
                for k in range(n):
                    res[k] = is_left_turn(points[i], points[j], points[k]) or is_colinear(points[i], points[j], points[k])
                if set(res) == {True}:
                    ''' for test '''
                    # print(points[i]),; print("\t"),; print(points[j]),; print("\t"),; print(res)

                    extreme_edges.append(line)

    # print(extreme_edges)
    extreme_edges_set = set(extreme_edges)

    ''' get vertices from extreme edges '''
    extreme_edge_vertex = []
    for index in range(len(extreme_edges)):
        line = extreme_edges[index]
        extreme_edge_vertex.append(line.start)
        extreme_edge_vertex.append(line.terminal)

    ''' get unique vertices from extreme edge vertices '''
    eev = list(set(extreme_edge_vertex))
    # print(eev)

    ''' for testing: displays content of non_extreme_points '''
    # for index in range(len(eev)):
    #     print(eev[index]),
    #     print("\t"),

    ''' for sorting extreme edge vertices '''
    centroid = Point(sum([point.x for point in eev])/len(eev),sum([point.y for point in eev])/len(eev))

    sorted_eev = copy.deepcopy(eev)
    sorted_eev.sort(key=lambda p: math.atan2(p.y-centroid.y,p.x-centroid.x))

    ''' for testing only '''
    # for index in range(len(sorted_eev)):
    #     print(sorted_eev[index]),
    #     print("\t"),

    ''' obtain sorted edges from sorted edge vertices '''
    sorted_edge = []

    num_sorted_vertices = len(sorted_eev)
    for index in range(num_sorted_vertices):
        edge = LineSegment(sorted_eev[index], sorted_eev[(index + 1) % num_sorted_vertices])
        sorted_edge.append(edge)

    ''' for testing only: sorted edges '''
    # for index in range(len(sorted_edge)):
    #     print(sorted_edge[index]),
    #     print("\t"),

    return(sorted_edge)

def gift_wrap_convex_hull_linked_list(point_linked_list):
    ''' Gift Wrap Algorithm implementation using Circular Doubly Linked List

        parameter: point_linked_list = Circular Doubly Linked List of sorted
                   points (in non decreasing order of Y-Coord)

        result: Circular Doubly Linked List of Convex Hull Points
    '''

    # result to return
    gift_wrap_linked_list = CircularDoublyLinkedList()

    # first point is the point with least Y- coordinate
    first_point = point_linked_list.head

    # take first point as reference, and set next point to None '''
    ref_point = first_point
    next_point = None

    while(True):
        # add reference point to result
        gift_wrap_linked_list.append(ref_point.data)

        # get next point in linked list
        next_point = ref_point.next

        # set cursor to head of linked list
        cursor = point_linked_list.head

        # for all node in linked list
        while(True):
            # if there exist a point counter-clockwise to next point, set that point as next point
            if(compute_area(ref_point.data, cursor.data, next_point.data) > 0.0):
                next_point = cursor

            # increment cursor to next node
            cursor = cursor.next

            # stop when cursor reach head of linked list again
            if(cursor == point_linked_list.head):
                break

        # set next point as reference point for next iteration
        ref_point = next_point

        # iterate until we reach head of linked list
        if(ref_point == point_linked_list.head):
            break

    return gift_wrap_linked_list

def graham_scan_convex_hull(points):
    ''' Graham Scan Algorithm

        parameter: points = array of given points

        result: Array of Convex Hull Points
    '''

    # num of points
    vertex_num = len(points)

    # if number of points are less than 4, then the input set of points
    # are the convex hull itself
    if vertex_num < 4:
        return points

    # result variable
    convex_hull_graham_scan = []

    # get min Y- Coord point
    sorted_points_inc_y = copy.deepcopy(points)
    sorted_points_inc_y.sort(key=lambda p: p.y)
    min_y_coord_point = sorted_points_inc_y[0]
    # print(min_y_coord_point)

    # sort points in anti-clockwise order wrt min_y_coord_point
    sorted_p = copy.deepcopy(points)
    sorted_p.sort(key=lambda p: math.atan2(p.y-min_y_coord_point.y,p.x-min_y_coord_point.x))

    ''' Graham Scan Algorithm begins here '''
    # add first three coordinates of sorted points in result
    convex_hull_graham_scan.append(sorted_p[0])
    convex_hull_graham_scan.append(sorted_p[1])
    convex_hull_graham_scan.append(sorted_p[2])

    ''' these are top of stack and next top of stack, using list (for testing)'''
    # print(point_stack[-1])
    # print(point_stack[-2])

    '''
        i = 3
        while(i < N):
            if left_turn(top(stack), next_top(stack), sorted_point(i)):
                stack.push(sorted_point[i])
                i++
            else:
                stack.pop()
    '''
    index = 3
    while(index < vertex_num):
        if is_left_turn(convex_hull_graham_scan[-2], convex_hull_graham_scan[-1], sorted_p[index]):
            convex_hull_graham_scan.append(sorted_p[index])
            index += 1
        else:
            convex_hull_graham_scan.pop()

    return convex_hull_graham_scan

def main():
    """ Main Function """

    print("CG LAB 4")
    print("Brihat Ratna Bajracharya\n19/075\n")

    ''' reads input file '''
    in_file = open(INPUT_FILE, 'r')

    ''' get number of points '''
    print("Enter number of points:"),
    points_num = int(in_file.readline())
    print(points_num)

    ''' reads coords of point '''
    input_coords = in_file.readline()
    input_coords_list = input_coords.split()
    # print(input_coords_list)

    ''' initialize vertex list '''
    points = [None] * points_num

    ''' get coordinates of each point '''
    for index in range(points_num):
        print(" Enter coordinates of point P{}:".format(index+1)),
        input_coords_point = input_coords_list[index].split(',')
        points[index] = Point(int(input_coords_point[0]), int(input_coords_point[1]))
        print(points[index])

    ''' FINDING CONVEX HULL BASED ON EXTREME POINTS '''
    convex_hull_exp_pt = get_extreme_points_based_convex_hull(points)

    print("\nConvex Hull (Extreme Points): ["),
    for index in range(len(convex_hull_exp_pt)):
        print(convex_hull_exp_pt[index]),
        if index != len(convex_hull_exp_pt) - 1:
            print(","),
    print("]")

    ''' FINDING CONVEX HULL BASED ON EXTREME EDGES '''
    convex_hull_exp_edges = get_extreme_edges_based_convex_hull(points)

    print("\nConvex Hull (Extreme Edges): ["),
    for index in range(len(convex_hull_exp_edges)):
        print(convex_hull_exp_edges[index]),
        if index != len(convex_hull_exp_edges) - 1:
            print("---"),
    print("]")

    ''' FINDING CONVEX HULL: GIFT WRAP ALGORITHM (USING CIRCULAR DOUBLY LINKED LIST) '''
    points_inc_order_of_y_coord = copy.deepcopy(points)
    points_inc_order_of_y_coord.sort(key=lambda point: point.y)

    point_linked_list = CircularDoublyLinkedList()

    for index in range(len(points)):
        point_linked_list.append(points_inc_order_of_y_coord[index])

    convex_hull_gift_wrap_linked_list = gift_wrap_convex_hull_linked_list(point_linked_list)
    convex_hull_gift_wrap_linked_list.display("Convex Hull (Gift Wrap) 2")

    ''' FINDING CONVEX HULL: GRAHAM SCAN ALGORITHM '''
    convex_hull_graham_scan = graham_scan_convex_hull(points)

    print("\nConvex Hull (Graham Scan): ["),
    for index in range(len(convex_hull_graham_scan)):
        print(convex_hull_graham_scan[index]),
        if index != len(convex_hull_graham_scan) - 1:
            print(","),
    print("]")

    print("\nDONE.")

if __name__ == '__main__':
    main()
      \end{spverbatim}
    \end{footnotesize}
  \end{spacing}

  \section*{\textbf{\underline{Output}}}
  \begin{spacing}{1}
    \begin{footnotesize}
      \begin{spverbatim}
$ ./cg_lab_4_convex_hull.py

CG LAB 4
Brihat Ratna Bajracharya
19/075

Enter number of points: 11
 Enter coordinates of point P1: (5, 8)
 Enter coordinates of point P2: (2, 7)
 Enter coordinates of point P3: (7, 7)
 Enter coordinates of point P4: (5, 6)
 Enter coordinates of point P5: (3, 5)
 Enter coordinates of point P6: (6, 5)
 Enter coordinates of point P7: (4, 4)
 Enter coordinates of point P8: (3, 3)
 Enter coordinates of point P9: (2, 2)
 Enter coordinates of point P10: (5, 2)
 Enter coordinates of point P11: (8, 3)

Convex Hull (Extreme Points): [ (3, 3) , (2, 2) , (5, 2) , (8, 3) , (7, 7) , (5, 8) , (2, 7) ]

Convex Hull (Extreme Edges): [ [(2, 2), (5, 2)] --- [(5, 2), (8, 3)] --- [(8, 3), (7, 7)] --- [(7, 7), (5, 8)] --- [(5, 8), (2, 7)] --- [(2, 7), (2, 2)] ]

Convex Hull (Gift Wrap) 2: [ (2, 2) (5, 2) (8, 3) (7, 7) (5, 8) (2, 7) ] #
Convex Hull (Graham Scan): [ (2, 2) , (5, 2) , (8, 3) , (7, 7) , (5, 8) , (2, 7) ]
DONE.
      \end{spverbatim}
    \end{footnotesize}
  \end{spacing}

  \begin{figure}[h!]
    \centering
    \begin{subfigure}[b]{0.2\linewidth}
      \includegraphics[width=\linewidth]{cg_lab_4_output_extreme_points.png}
      \caption{Using \\Extreme Points}
    \end{subfigure}
    \hspace{1in}
    \begin{subfigure}[b]{0.2\linewidth}
      \includegraphics[width=\linewidth]{cg_lab_4_output_extreme_edges.png}
      \caption{Using \\Extreme Edge}
    \end{subfigure}
    \hspace{1in}
    \begin{subfigure}[b]{0.2\linewidth}
      \includegraphics[width=\linewidth]{cg_lab_4_output_gift_wrap.png}
      \caption{Using \\Gift Wrap/Graham Scan}
    \end{subfigure}
    \caption{Convex Hull}
    \label{fig:convex_hull}
  \end{figure}

  \vspace{1cm}

  \section*{\textbf{\underline{Input File}}\footnote{\url{https://github.com/Brihat9/CG/blob/master/cg_lab_4_input_file}}}
  \begin{spacing}{1}
    \begin{footnotesize}
      \begin{spverbatim}
11
5,8 2,7 7,7 5,6 3,5 6,5 4,4 3,3 2,2 5,2 8,3
      \end{spverbatim}
    \end{footnotesize}
  \end{spacing}

\end{document}


\documentclass[]{article}
\RequirePackage{amsmath}

\usepackage{graphicx}
\usepackage{amssymb}
\usepackage{color}
\usepackage{hyperref}
\usepackage{algorithm}
\usepackage{algpseudocode}
\bibliographystyle{IEEEtran}

\newcommand{\knote}[1]{\textcolor{green}{A: {#1}}}
\newcommand{\dnote}[1]{\textcolor{red}{D: {#1}}}
\newcommand{\vk}[1]{\textcolor{blue}{V: {#1}}}
\newcommand{\lnote}[1]{\textcolor{cyan}{L: {#1}}}
\newcommand{\Name}{$Autolykos$}
\def\Let#1#2{\State #1 $:=$ #2}
\def\LetRnd#1#2{\State #1 $\gets$ #2}

\newcommand{\pk}{\mathsf{pk}}
\newcommand{\sk}{\mathsf{sk}}

\begin{document}
    \title{\Name: The Ergo Platform PoW Scheme}

    \author{Alexander Chepurnoy\thanks{Autolykos v. 1 and v. 2}, Vasily Kharin\thanks{Autolykos v. 1}, Dmitry Meshkov\thanks{Autolykos v. 1}}
    \date{December, 04, 2020\\v2.0}

    \maketitle

    \abstract{
        This document describes family of Autolykos Proof-of-Work algorithms used in Ergo cryptocurrency.
        From block 1 until 417,792 Autolykos version 1 is used on Ergo mainnet. Since block 417,792
        Autolykos version 2 is used.
    }

    \section{Autolykos version 2}

    Autolykos version 2 is following Autolykos version 1 defined in Section~\ref{av1}, but with certain modifications made:
     \begin{itemize}
        \item{} non-outsourceability switched off. It turns out~(based on more than 1 year of non-outsourceable PoW experience) that non-outsourceable
                PoW is not attractive to small miners.
        \item{} now algorithm is trying to bind an efficient solving procedure with a single table of ~2 GB
        \item{} table size (memory requirements of a solving algorithm) grows with time
        \item{} now table is depending on block height only, so there is no penalization for recalculating
                block candidate for the same height
     \end{itemize}

    Solution verification and proving are given in Alg.~\ref{alg:verify2} and Alg.~\ref{alg:prove2}.

    Please note that:
    \begin{enumerate}
        \item{} $H()$ is now not $mod\ q$ , but ordinary $blake2b256$ with 256-bit output
        \item{} $takeRight(n, \cdot)$ is taking $n$ least significant (right) bytes (from 32 bytes array)
        \item{} $sum$ is always about 256 bits (32 bytes)
        \item{} $h$ is height of a block (32 bits = 4 bytes)
        \item{} $N$ value is growing with time as follows. Until block $614,400$, $N = 2^{26} = 67,108,864$.
                From this block, and until block $4,198,400$, every 51,200 blocks $N$ is increased by 5 percent.
                Since block $4,198,400$, value of $N$ is fixed and equals to $2,143,944,600$. Test vectors for
                $N$ values are provided in Table \ref{ntbl}.

        \item{} $M$ is still equal to $8 * 1,024$ (bytes)
    \end{enumerate}

    \begin{algorithm}[H]
        \caption{Solution verification and proving}
        \label{alg:verify2}
        \begin{algorithmic}[1]
            \State \textbf{Input}: $m, nonce$
            \Let{$i$}{$takeRight(8, H(m || nonce))\ mod\ N$}
            \Let{$e$}{$takeRight(31, H(i || h || M))$}
            \Let{$J$}{$genIndexes(e || m || nonce)$}
            \Let{$f$}{$\sum_{j \in J} takeRight(31, H(j || h || M))$}
            \State require $H(f) < b$
        \end{algorithmic}
    \end{algorithm}

    \begin{algorithm}[H]
        \caption{Block mining}
        \label{alg:prove2}
        \begin{algorithmic}[1]
            \State \textbf{Input}: upcoming block header hash $m$, block height $h$
            \State Calculate $r_{i \in [0,N)} = takeRight(31, H(j || h || M))$
            \While{$true$}
            \LetRnd{$nonce$}{$\mathsf{rand}$}
            \Let{$i$}{$takeRight(8, H(m || nonce))\ mod\ N$}
            \Let{$e$}{$takeRight(31, H(i || h || M))$}
            \Let{$J$}{$genIndexes(e || m || nonce)$}
            \Let{$f$}{$\sum_{j \in J}{r_j}$}
            \If{$H(f) < b$}
            \State \Return $(m, nonce)$
            \EndIf
            \EndWhile
        \end{algorithmic}
    \end{algorithm}

    \begin{table}[h]
    \begin{tabular}{| l | l |}
    \hline
    Height & $N$ value  \\
    500,000 & 67,108,864 \\
    600,000 & 67,108,864 \\
    614,400 & 70,464,240 \\
    700,000 & 73,987,410 \\
    788,400 & 81,571,035 \\
    1,051,200 & 104,107,290 \\
    4,198,400 & 2,143,944,600 \\
    24,198,400 & 2,143,944,600 \\
    \hline
    \end{tabular}
    \label{ntbl}
    \caption{Test vectors for $N$ values}
    \end{table}

    \section{Autolykos version 1}
    \label{av1}

    \subsection{Introduction}

    Security of Proof-of-Work blockchains relies
    on multiple miners trying to produce new blocks by
    participating in PoW puzzle lottery, and the network is secure if the
    majority of them are honest. However, the reality becomes much more complicated
    than the original one-CPU-one-vote idea from the Bitcoin whitepaper\cite{nakamoto2008bitcoin}.

    The first threat to decentralization came from mining pools -- miners tend
    to unite in mining pools.
    Regardless of the PoW algorithm number of pools controlling more then 50\% of
    computational power is usually quite small: 4 pools in Bitcoin, 2 in Ethereum, 3 in ZCash, etc.
    This problem led to the notion of non-outsourceable puzzles~\cite{miller2015nonoutsourceable,daian2017piecework}.
    These are the puzzles constructed in such a way that if a mining pool outsources the puzzle
    to a miner, miner can recover pool's private key and steal the reward with a non-negligible probability.
    However the existing solutions either have too large solution size (kilobyte is already
    on the edge of acceptability for distributed ledgers) or very specific and
    can not be modified or extended in any way without breaking non-outsourceability.

    The second threat to cryptocurrencies decentralization is that ASIC-equipped miners are
    able to find PoW solutions orders of magnitude faster and more efficiently
    than miners equipped with the commodity hardware. In order to reduce the
    disparity between the ASICs and regular hardware, memory-bound computations
    where proposed in~\cite{dwork2003memory}. The most interesting practical
    examples are two
    asymmetric memory-hard PoW schemes which require significantly less memory
    to verify a solution than to find it~\cite{biryukov2017equihash,ethHash}.
    Despite the fact that ASICs already exist for both of them~\cite{ETHAsics,EquihashAsics},
    they remain the only asymmetric memory-hard PoW algorithms in use.

    In this paper we propose \Name{} --- new asymmetric memory-hard non-outsourceable PoW puzzle.
    In Section~\ref{puzzle} we provide a full
    specification of \Name, while in Section~\ref{discussion} we discuss its
    properties. Few auxiliary algorithms are placed in~\nameref{appendix}.

    \section{Autolykos v.1 puzzle}
    \label{puzzle}

    The proposed scheme requires following components:
    \begin{enumerate}
        \item Cyclic group $\mathbb{G}$ of prime order~$q$ with fixed generator~$g$
        and identity element~$e$.
        Secp256k1 elliptic curve is used for this purposes.
        \item Number of elements $k$ required in the solution. Value $k=32$ is used in
        implementation.
        \item Number $N$ of elements in the list
        $R\subset\mathbb{Z}/q\mathbb{Z}$ to be stored in miner's memory.
        Value $N=2^{26}$ is used in implementation.
        \item Hash function $H$ which returns the values in $\mathbb{Z}/q\mathbb{Z}$.
        Particular implementation is based on Blake2b256 and is described in Alg.\ref{alg:H}.
        \item Hash function $genIndexes$ which returns a list of numbers from
        $0\dots(N-1)$ of size $k$.
        It is based on Blake2b256 and is described in Alg.\ref{alg:genIndexes}.
        \item Target interval parameter $b$, that is recalculated via difficulty adjustment rules.
        \item Constant message $M=[0,\dots,1023].flatMap(i => Longs.toByteArray(i))$ that is used to enlarge message size and increase elements calculation time.
    \end{enumerate}

    \Name{} is based on one list $k$-sum problem: miner should find
    $k$ elements from the pre-defined list $R$ of size $N$, such that
    $\sum_{j \in J} r_{j} - sk = d$ is in the interval $\{-b,\dots,0,\dots,b\mod q\}$.
    In addition, we require set of element indexes $J$ to be obtained
    by one-way pseudo-random function $genIndexes$. This prevents optimizations as
    soon as it is hard to find such a seed,
    that $genIndexes(seed)$ returns the desired indexes.

    Thus we assume that the only option for miner is to use the simple brute-force algorithm~\ref{alg:prove} to
    create a valid block.

    \begin{algorithm}[H]
        \caption{Block mining}
        \label{alg:prove}
        \begin{algorithmic}[1]
            \State \textbf{Input}: upcoming block header hash $m$, key pair $pk=g^{sk}$
            \State Generate randomly a new key pair $w=g^x$
            \State Calculate $r_{i \in [0,N)}=H(j||M||pk||m||w)$
            \While{$true$}
            \LetRnd{$nonce$}{$\mathsf{rand}$}
            \Let{$J$}{$genIndexes(m||nonce)$}
            \Let{$d$}{$\sum_{j \in J}{r_j} \cdot x - sk \mod q$}
            \If{$d < b$}
            \State \Return $(m,pk,w,nonce,d)$
            \EndIf
            \EndWhile
        \end{algorithmic}
    \end{algorithm}

    Note that although the mining process utilizes private keys, solution itself
    only contains public keys. Solution verification can be performed by Alg.~\ref{alg:verify}.

    \begin{algorithm}[H]
        \caption{Solution verification}
        \label{alg:verify}
        \begin{algorithmic}[1]
            \State \textbf{Input}: $m,pk,w,nonce,d$
            \State require $d < b$
            \State require $pk,w\in \mathbb{G}$ and $pk,w \ne e$
            \Let{$J$}{$genIndexes(m||nonce)$}
            \Let{$f$}{$\sum_{j \in J} H(j||M||pk||m||w)$}
            \State require $w^f = g^dpk$
        \end{algorithmic}
    \end{algorithm}

    \subsection{Discussion}
    \label{discussion}

    First, notice that in Algorithm~\ref{alg:prove} we refer to construction
    $f(m,nonce,w,pk)=\sum_{j\in genIndexes(m||nonce)} H(j||M||pk||w)$ as a hash
    function. Public key plays a role of commitment. Therefore, the pair
    $(pk,d)$ is a Schnorr signature with a public key $w$ over the message
    $(m,nonce)$ with a hash function $f$. If one denotes $e$ the corresponding
    value of $f$, and pass to more common notations:
    $e=f(m,nonce,w,w^eg^{-d})$. The puzzle consists in trying
    different nonces and keys in order for signature to satisfy
    $d\in\{-b,\dots,0,\dots,b\}$. Security follows from the security of Schnor
    signatures, and outsourcing the puzzle is equivalent to outsourcing the
    signature (or parts of signature creation routine). The only difference from
    conventional setup is the design of function $f$. It must be constructed in such
    a way that efficient massive evaluations with different nonces require
    allocating large amount of memory (benefitting from data reuse), whereas
    single evaluation on verifier's side can be done ``on fly''.

    To achieve this, algorithm~\ref{alg:prove} requires to keep the whole list $R$ during the main loop.
    Every pre-calculated hash occupies 32 bytes, so the whole list of $N$ elements
    occupies $N \cdot 32 = 2 Gb$ of memory.
    For sure, a miner can recalculate these elements ``on fly'' during the main loop and
    thus reduce memory requirements.
    However in such a case the number of calls of $H$ will significantly grow up~(e.g.
    assuming GPU hashrate $G = 2^{30} H/s$~\cite{gpuHashrate} and block interval $t=120~s$,
    every element will be used $(G / N) \cdot k \cdot t = 3 \cdot 10^4$ times on average.)
    reducing miner's efficiency and profit.

    While list $R$ is quite big, it's filling consumes quite a lot of time: our initial implementation~\cite{ergoMiner}
    consumed ~25 seconds on Nvidia GTX 1070 to fill list $R$. This part, however, may be sufficiently
    optimized if miner in addition stores a list of unfinalized hashes $u_{i \in [0,N)}=H(i||M||pk$
    in memory, consuming 5 more Gigabytes of it. In such a case this work to calculate unfinalized hashes should
    be done only once during mining initialization while finalizing them and filling the list $R$
    for the new header will only consume few milliseconds~(for about 50 ms on Nvidia GTX 1070).

    The protocol is quite efficient in terms of solution size and verification time: it consists of 2 public keys of
    size 32 bytes, number $d$ that is at most 32 bytes
    (but contains a lot of leading zeros in case of the small target $b$) and an
    8-bytes long nonce. Header verification requires verifier to calculate 1 $genIndexes$
    hash, $k$ hashes $H$ and perform two exponentiations in the group. Reference
    Scala implementation~\cite{ergoGit} allows verifying block header in 2
    milliseconds on Intel Core i5-7200U, 2.5GHz.

    \bibliography{references}

    \section*{Appendix}
    \label{appendix}

    Implementation of hash function $H$ which returns the values in $\mathbb{Z}/q\mathbb{Z}$:

    \begin{algorithm}[H]
        \caption{Numeric hash}
        \label{alg:H}
        \begin{algorithmic}[1]
            \Function{H}{$input$}
            \Let{$validRange$}{$(2^{256} / q) \cdot q$}
            \Let{$hashed$}{$Blake2b256(input)$}
            \If{$hashed < validRange$}
            \State \Return $hashed.mod(q)$
            \Else
            \State \Return $H(hashed)$
            \EndIf
            \EndFunction
        \end{algorithmic}
    \end{algorithm}

    Implementation of hash function $genIndexes$ which returns a list of size $k$ with numbers in $0\dots (N-1)$:

    \begin{algorithm}[H]
        \caption{Index generator}
        \label{alg:genIndexes}
        \begin{algorithmic}[1]
            \Function{genIndexes}{$seed$}
            \Let{$hash$}{$Blake2b256(seed)$}
            \Let{$extendedHash$}{$hash||hash$}
            \State \Return $(0\dots{k-1}).map(i => extendedHash.slice(i,i+4).mod(N))$
            \EndFunction
        \end{algorithmic}
    \end{algorithm}

\end{document}


\documentclass{article}
\newsavebox{\oldepsilon}
\savebox{\oldepsilon}{\ensuremath{\epsilon}}
\usepackage[minionint,mathlf,textlf]{MinionPro} % To gussy up a bit
\renewcommand*{\epsilon}{\usebox{\oldepsilon}}
\usepackage[margin=1in]{geometry}
\usepackage{graphicx} % For .eps inclusion
%\usepackage{indentfirst} % Controls indentation
\usepackage[compact]{titlesec} % For regulating spacing before section titles
\usepackage{adjustbox} % For vertically-aligned side-by-side minipages
\usepackage{array, amsmath,  mhchem}
\usepackage[hidelinks]{hyperref}
\usepackage{courier, subcaption}
\usepackage{multirow, enumerate}
\usepackage[autolinebreaks,framed,numbered]{mcode}
\usepackage{float}
\restylefloat{table}

\pagenumbering{gobble}
\setlength\parindent{0 cm}
\renewcommand{\arraystretch}{1.2}
\begin{document}
\large

MCB 135 Problem Set 6 \hfill Due Wednesday, March 25, 2015 at 2:30 PM

\section*{Problem 1: Band pass filter (55 points)}

As many jet-setters discover, circadian clocks are not useful unless their phase is set appropriately. Entrainment is the process of setting a biological clock's phase in response to external cues such as sunlight. Unfortunately, entrainment cues themselves may be noisy and require filtering.\\

Consider an entrainment system whose input is the ambient light level $x(t)$, which oscillates with 24-hour period but is subject to many sources of variation. The system's output $y(t)$ would ideally be sinusoidal with period 24 hours and the same phase as the circadian signal.\\

\begin{center}
\includegraphics[width=.7\textwidth]{sun.pdf}
\end{center}

The time course at left shows $x(t)$ measurements taken every hour, beginning at noon, for 900 days. $x(t)$ was then decomposed into a combination of sine waves of different frequencies: the \textit{power spectral density }(PSD) plot at right gives the relative power of each wave vs. its frequency, $\omega$. The time course data and code used to generate the PSD are available on the course website.

\begin{enumerate}[a)]
\setlength{\itemsep}{0pt}
\item Which of the two major peaks in the PSD represents the signal we wish to amplify? What is the source of the other peak?\\

{\color{red}
The peak at $\omega = 1$ cycle per dayis the circadian signal which we wish to amplify. The second peak, with a frequency $\omega = 1$ cycle per 365 days is likely caused by annual fluctuations in average illumination.
}

\item Determine the closed loop transfer function for the system depicted below in terms of $K(s)$.

\begin{center}
\includegraphics[width=.3\textwidth]{feedback.pdf}
\end{center}

{\color{red}
\begin{eqnarray*}
\tilde{y} & = & \left[ \tilde{x} - K(s) \tilde{y} \right] \\
\textrm{Closed loop transfer function } H(s) = \frac{\tilde{y}}{\tilde{x}} & = & \frac{1}{1+K(s)}
\end{eqnarray*}
}

\item What type of controller can be used to preferentially amplify high frequencies? Low frequencies?\\

{\color{red}
A derivative controller preferentially amplifies high frequencies, and an integral controller preferentially amplifies low frequencies.
}

\item Combine your answers in part (c) to choose a form for $K(s)$ so that the closed loop system filters out both high and low frequency noise. Include appropriate units on any constants\footnote{Hint: What is one period in radians? As you complete the remaining questions, it should become clear whether your units were selected properly.}.\\

{\color{red}
Choose $K(s) = \tau_d s + \frac{1}{\tau_i s}$ so that both high and low frequency noise are detected by the feedback loop and thus subtracted from the input signal; the closed loop transfer function is therefore:
\[ H(s) = \frac{s}{\tau_d s^2 + s + \frac{1}{\tau_i}} \]
The constants should be chosen so that there is no attenuation at the circadian signal's frequency ($\omega=1$ cycle per day = $2\pi$ radians per day). A trial-and-error approach to constant choice is acceptable; alternatively, we can calculate the magnitude of the closed loop transfer function at $\omega = 2\pi$ radians/day and find a relation on $\tau_d$ and $\tau_i$ from there:
\begin{eqnarray*}
1 = \left| H(s) \right|_{s=i\omega} & = &\left| \frac{i\omega}{-\tau_d \omega^2 + i \omega + \frac{1}{\tau_i}} \cdot \frac{-\tau_d \omega^2 - i \omega + \frac{1}{\tau_i}}{-\tau_d \omega^2 - i \omega + \frac{1}{\tau_i}} \right|\\
& = &  \left| \frac{\omega^2 + i\omega \left( -\tau_d \omega^2 + \frac{1}{\tau_i}\right)}{\omega^2 + \left( -\tau_d \omega^2 + \frac{1}{\tau_i}\right)^2} \right| = \frac{\omega \sqrt{\omega^2 + \left( -\tau_d \omega^2 + \frac{1}{\tau_i}\right)^2}}{\omega^2 + \left( -\tau_d \omega^2 + \frac{1}{\tau_i}\right)^2}\\
\sqrt{\omega^2 + \left( -\tau_d \omega^2 + \frac{1}{\tau_i}\right)^2} & = & \omega \implies \tau_d \tau_i = \frac{1}{\omega^2} = \frac{1}{4\pi^2} \textrm{ days$^2$ per radian$^2$}
\end{eqnarray*}
For example, we could choose $\tau_d = \frac{20}{2 \pi}$ days per radian and $\tau_i = \frac{1}{20 \times 2\pi}$ days per radian.
}

\item Construct a Bode plot for your closed loop system. Will the phase of the output be accurate for oscillations with a 24-hour period?\\

{\color{red}

All figures generated for this problem are included here for simplicity:

\begin{center}
\includegraphics[width=\textwidth]{problem1figs.pdf}
\end{center}

The Bode plot for $H(s)$ (2nd from top left) shows the magnitude peak of 0 dB (1:1 ratio of input to output) at $\omega = 2\pi$ radians/day that we desired. At that frequency, the phase difference between input and output is zero, so we expect the phase of the output to accurately reflect the phase of the circadian signal.
}

\item Use MATLAB's \mcode{lsim()} function with the time course data and your closed loop transfer function to simulate the output of your system, $y(t)$. Include plots of $y(t)$ with appropriate windows to:
\begin{itemize}
\item Confirm that your system's output is dominated by oscillations with a 24-hour period.
\item Show the range of variation in amplitude over 900 days.
\item Indicate the ``burn-in" time, i.e., time elapsed before the system's output has reasonably steady phase and amplitude.
\end{itemize}

{\color{red}
See the early, middle, and long-term timecourses included in the composite figure above. The middle timecourse shows oscillations with a period of 1 day. The range in amplitude is shown in the long-term timecourse and seems to be a rather large spread. The early timecourse shows the slow initial increase in amplitude of the signal over the course of roughly 15-20 days: this is an estimate of the ``burn-in" time. (Note the relationship to our choice of $\tau_i$.)
}

\item Are there trade-offs between shorter burn-in time and variation in amplitude for the system you've designed? Demonstrate your conclusion by showing a plot with a different choice of parameters.\\

{\color{red}
For comparison, the following figure shows the results when we use $\tau_d=20$ and $\tau_i=\frac{1}{20(2\pi)^2}$ instead:

\begin{center}
\includegraphics[width=\textwidth]{problem1figs2.pdf}
\end{center}

These constants give an output signal with greater uniformity in amplitude, but with a longer burn-in time of approximately 90-120 days. A general trade-off is expected between burn-in time and consistency in output signal amplitude because both depend on the choice of integral control time constant.
}

\item Simulate a ``free run" by setting $x(t)$ to zero at some time after the burn-in. How long does your system continue to oscillate appreciably?\\

{\color{red} The composite figures above show the result when we set $x(t)$ to zero for all times $t>500$ days. The length of time for which the system will continue to oscillate noticeably depends on the choice of constants used, e.g. about 20 days for the first example and about 120 days for the second example, as expected from the choice of $\tau_i$.\\

All code used in this problem appears below (an alternative transfer function used in problem 2 has been commented out):
}

\begin{lstlisting}
function [] = bode_timecourse_psd()
    % Load the data in from the file
    a = tdfread('illumination.tsv');
    t = a.x0';
    x = a.x70x2E58942367627401';

    % PSD for input (for your reference only)
    figure
    subplot(2,4,1)
    Fs = 24;
    nfft = 2^nextpow2(length(x));
    Pxx = abs(fft(x,nfft)).^2/length(x)/Fs;
    Hpsd2 = dspdata.psd(Pxx(1:length(Pxx)/2),'Fs',Fs);
    plot(Hpsd2)
    axis([1E-3 10 -50 50])
    set(gca,'XScale','log')
    xlabel('\omega (days^{-1})')
    title('Power spectral density for input')

    % Bode plot for this transfer function
    % Resonator
    %gamma=0.001*2*pi;
    %k = 2*pi;
    %my_tf = tf([1 gamma],[1, 2*gamma, gamma^2 + k^2]);

    % Band pass
    tau_i = 1/(20*2*pi);
    tau_d = 20/(2*pi);
    my_tf = tf([1 0],[tau_d, 1, 1/tau_i]);

    subplot(2,4,2)
    bode(my_tf)
    xlabel('Frequency (radians/day)')

    % Simulate output
    y = lsim(my_tf,x,t);

    % Early timecourse (shows burn-in time)
    subplot(2,4,3)
    plot(t,y)
    axis([0 30 -2 2])
    title('Early timecourse')
    xlabel('Time (days)')
    ylabel('Relative illumination')

    % Middle timecourse (shows 24-hour oscillation and phase)
    subplot(2,4,4)
    plot(t,y)
    axis([500 505 -2 2])
    title('Middle timecourse')
    xlabel('Time (days)')
    ylabel('Relative illumination')

    % Full timecourse (shows variation in amplitude)
    subplot(2,4,5)
    plot(t,y)
    axis([0 900 -2 2])
    title('Long-term timecourse')
    xlabel('Time (days)')
    ylabel('Relative illumination')

    % PSD for output (for your reference only)
    subplot(2,4,6)
    Fs = 24;
    nfft = 2^nextpow2(length(y));
    Pyy = abs(fft(y,nfft)).^2/length(y)/Fs;
    Hpsd2 = dspdata.psd(Pyy(1:length(Pyy)/2),'Fs',Fs);
    plot(Hpsd2)
    axis([1E-3 10 -50 50])
    set(gca,'XScale','log')
    xlabel('\omega (days^{-1})')
    title('Power spectral density for output')

    % Simulated free run -- input disappears at t=500 days
    x(24*500:end) = zeros(size(x(24*500:end)));
    y = lsim(my_tf,x,t);

    % Free run results
    subplot(2,4,7)
    plot(t,y)
    axis([500 550 -2 2])
    title('Simulated free run (starting when x(t)=0)')
    xlabel('Time (days)')
    ylabel('Relative illumination')

end
\end{lstlisting}
\end{enumerate}

\section*{Problem 2: Resonator (25 points)}

An alternative approach to amplify oscillations at a frequency of interest uses resonant systems. Consider the following system of two transcription factors, $A$ and $B$: expression of $A$ is driven by an input signal $x(t)$ but is repressed by $B$. $A$ activates expression of $B$. Both transcription factors are subject to dilution/degradation.

\begin{eqnarray*}
\frac{da}{dt} & = & x(t) - k b - \gamma a\\
\frac{db}{dt} & = & ka - \gamma b
\end{eqnarray*}

The output of this system is regarded to be the concentration $a(t)$.

\begin{enumerate}[a)]
\setlength{\itemsep}{0pt}
\item Apply a Laplace transformation to the system and rearrange to find the system's closed loop transfer function, $\frac{\tilde{a}(s)}{\tilde{x}(s)}$.\\

{\color{red} We will assume initial concentrations are zero to simply the transformation.
\begin{eqnarray*}
s\tilde{b} & = & k\tilde{a} - \gamma \tilde{b} \implies \tilde{b}  = \frac{k \tilde{a}}{s + \gamma}\\
s\tilde{a} & = & \tilde{x} - k\tilde{b} - \gamma \tilde{a} \implies \frac{\tilde{a}}{\tilde{x}} = \frac{1}{s + \gamma + \frac{k^2}{s+\gamma}} = \frac{s + \gamma}{s^2 + 2\gamma s + \gamma^2 + k^2}
\end{eqnarray*}
}

\item Prepare a Bode plot of this system with $\gamma=0.002 \pi $, $k=2\pi$.\\

{\color{red}
This figure was generated using the same code as above, with the transfer function for the resonator uncommented and some plotting bounds changed.

\begin{center}
\includegraphics[width=\textwidth]{resonator.pdf}
\end{center}

}

\item Repeat problem 1f using the resonator transfer function. Compare the result to your band pass filter's output.\\

{\color{red}
The resonator performs comparably to the band pass filter with small integration constant: the burn-in time is long and the amplitude of the output is relatively consistent. One notable difference is that the circadian signal has been amplified, whereas the band pass filter merely avoided attenuating this signal.

}

\end{enumerate}

\section*{Problem 3: Alternative coherent feedforward loop (adapted from Alon 4.5, 20 points)}

\begin{minipage}[b]{0.1\linewidth}
\includegraphics[width=\textwidth]{c3ffl.pdf}
\end{minipage}
\hspace{0.5cm}
\begin{minipage}[b]{0.85\linewidth}
Solve the dynamics of the type-3 coherent FFL (shown at left), assuming AND logic at the $Z$ promoter, in response to (i) a step increase and (ii) a step decrease in the concentration of $X$. Here, AND logic means that $Z$ is produced only if both $X$ and $Y$ are below their threshold concentrations for promoter binding. Are there delays? What logic gate does this circuit embody at steady-state? Compare your answers to the type-1 coherent FFL described in class.\\

\end{minipage}\\
{\color{red}
Define $K_X$ and $K_Y$ to be the threshold concentrations for activity of $X$ and $Y$.
\begin{eqnarray*}
\frac{dY}{dt} & = & \alpha_Y \Theta \left( X > K_ X \right) - \beta_Y Y\\
\frac{dZ}{dt} & = & \alpha_Z \Theta \left( X < K_ X \right) \Theta \left( Y < K_ Y \right) - \beta_Z Z
\end{eqnarray*}

\subsection*{Case one: $[X]<K_X \to [X] > K_X$}

We assume that prior to the step at $t=0$, the system has reached equilibrium with $X$ below its activity threshold: setting both time derivatives equal to zero, we find that $Y(0)=0$ and $Z(0) = \alpha_Z/\beta_Z$. After the step, $Y$ production immediately begins due to activation by $X$:
\[ \frac{dY(t \geq 0)}{dt} = \alpha_Y - \beta_Y Y \textrm{ and } Y(0) = 0  \implies Y(t \geq 0) = \frac{\alpha_Y}{\beta_Y} \left( 1 - e^{-\beta_Y t} \right) \]
After the step, $Z$ production immediately ceases due to repression by $X$:
\[ \frac{dZ(t \geq 0)}{dt} = - \beta_Z Z \textrm{ and } Z(0) = \frac{\alpha_Z}{\beta_Z} \implies Z(t \geq 0) = \frac{\alpha_Z}{\beta_Z} e^{-\beta_Z t} \]

\subsection*{Case two: $[X]>K_X \to [X] < K_X$}

We assume that prior to the step at $t=0$, the system has reached equilibrium with $X$ above its activity threshold: setting both time derivatives equal to zero, we find that $Y(0)=\alpha_Y/\beta_Y$ and $Z(0) = 0$. After the step, $Y$ production immediately ceases due to loss of activation by $X$:
\[ \frac{dY(t \geq 0)}{dt} = - \beta_Y Y \textrm{ and } Y(0) = \frac{\alpha_Y}{\beta_Y}  \implies Y(t \geq 0) = \frac{\alpha_Y}{\beta_Y} e^{-\beta_Y t} \]
In particular, $Y$ will fall below its activity threshold at time $\tau$:
\[ \frac{\alpha_Y}{\beta_Y} e^{-\beta_Y t} = \tau \implies \tau = \frac{1}{\beta_Y} \ln \left( \frac{\alpha_Y}{\beta_Y K_Y} \right) \]
$Z$ production commences at time $\tau$ when repression by both $X$ and $Y$ has lifted:
\[ \frac{dZ(t \geq \tau)}{dt} = \alpha_Z - \beta_Z Z \textrm{ and } Z(0) = Z(\tau) = 0 \implies Z(t \geq \tau) = \frac{\alpha_Z}{\beta_Z} \left( 1 - e^{-\beta_Z (t-\tau)} \right) \]

\subsection*{Summary and comparison}

The C3-FFL with AND logic has a time delay only for the ``off" step, whereas the C1-FFL with AND logic has a time delay only for the ``on" step. Furthermore, the C3-FFL implements ``NOT X" logic at steady state: by comparison, the C1-FFL implements ``X" logic at steady state.

}

\end{document}

problem set keys/ps6/tex/ps6 answer key.tex


\subsection{Support vector classifiers for multiple classes}


\documentclass[../main.tex]{subfiles}

\begin{document}

Reinforcement Learning deals with an agent trying to maximize some reward signal by interacting with an environment. In most cases, the agent is given little to no knowledge about the environment and so must explore the environment to understand how to maximize this signal. The task of finding a good way of interacting with the environment is known as the \textit{exploration problem}.

We propose a way to use Local Outlier Factors from Unsupervised Learning as a way of incentivizing an agent to explore the environment in a uniform manner. This uniform method of exploration is intrinsically different to exploring the environment randomly. Randomly exploring an environment is likely to entail spending much more time in easily accessible parts of the environment and much less time in remote areas of the environment whereas a uniform exploration strategy should spend roughly equal time in both. In domains where it essential that the agent visits remote parts of the environment, a uniform exploration policy will be significantly better than a random exploration policy.

Finding a good exploration policy has long been an important problem in Reinforcement Learning, so a decent amount of work has been done in this area. For example, Thrun considered the question of whether exploration should be directed or undirected \cite{Thrun:1992:EER:865072}. Some time later Barto considered what the analogy of the psychological concept of intrinsic motivation, which is deeply related to the idea of exploration, would be in Reinforcement Learning \cite{Barto2013}. More recently Bellemare et al. developed a novel method of guiding exploration using pseudo-counts \cite{DBLP:conf/nips/BellemareSOSSM16}. However, to our knowledge, the idea of using outliers and Unsupervised Learning as a means of guiding exploration is as of yet unexplored.

This work deals with two intersection areas: Reinforcement Learning and Unsupervised Learning. This intersection means that to understand this work a reader first needs to understand both Local Outlier Factors and Reinforcement Learning. Therefore we go through the necessary background on what Reinforcement Learning is in Section~\ref{sec:reinforcement_learning} and then what Local Outlier Factors are in Section~\ref{sec:local_outlier_factor}. After that, we elaborate on our proposed method in Section~\ref{sec:methods}. Following that, we perform an empirical evaluation of our method in Section~\ref{sec:experimental_evaluation}. Finally we conclude in Section~\ref{sec:conclusions}.

\subsection{Reinforcement Learning}
\label{sec:reinforcement_learning}

Reinforcement Learning \cite{DBLP:books/lib/SuttonB98}is a branch of machine learning that considers the problem of an agent interacting with an environment to try and maximize some reward signal (see Figure~\ref{fig:reinforcement_learning}). Specifically, at each discrete timestep $t$, when the environment is in state $S_t$, the agent takes an action $A_t$, and in response, the environment changes its state to a new state, $S_{t + 1}$, and rewards the agent with some real number, $R_{t + 1}$.

\begin{figure}[h]
    \centering
    \includegraphics[width=14cm]{{reinforcement_learning.pdf}}
    \caption{Visualization of the Reinforcement Learning Problem}
    \label{fig:reinforcement_learning}
\end{figure}

We consider two kinds of domains in Reinforcement Learning: episodic and continuing domains. In episodic domains, the agent begins in some start state and continues interacting with the environment until it reaches some terminal state. The objective of the learning is then to find a set of rules, or a \textit{policy}, by which it selects an action to take in the current state such that the expected total reward it receives over the course of an episode, or the expected value of the \textit{return}, is maximized. We write the return for an episodic task with $n$ total timesteps as follows:
\begin{equation}
    \label{eqn:episodic_return}
    G_t = \sum_{i=t}^n R_i
\end{equation}

While this definition suffices for episodic domains, in continuing domains there are no terminal states, but instead, we consider rewards to be better when they are received sooner. Specifically, when the agent is picking an action for the timestep $t$, it considers a reward $R_{t + k}$ to be worth $\gamma^{k - 1}R_{t + k}$ where $\gamma \in [0, 1)$ is known as the \textit{discount factor}. In this domain we write the return as follows:
\begin{equation}
    \label{eqn:continuing_return}
    G_t = \sum_{i=t}^\infty \gamma^{i - t - 1}R_i
\end{equation}

The objective of the learning in a continuous domain is then to find a policy by which it selects an action to take in the current state such that the expected sum of discounted rewards, or the expected value of Equation~\ref{eqn:continuing_return}, is maximized. The objective of learning in a continuous domain would be identical to the objective of learning in an episodic domain if the discount factor is equal to $1$ and the episode had infinite length, both of which are not generally allowed in this dichotomy. Using the definitions of return as mentioned above, we can formalize what it means for a state, or the act of taking an action in a state, to be valuable.

We say the value of a state when the agent is following some policy is the expected return after entering that state. We write the value of a state $S$ at time $t$ while the agent is following a policy $\pi$ as follows:
\begin{equation}
    \label{eqn:state_value}
    v_\pi(S_t) = \mathbbm{E}_\pi \left[G_t\right]
\end{equation}

The value of a state tells us how "good" it is to be in a state if we want to maximize the return. However, without a model of transitions between states, it does not give us any knowledge of how to pick a "good" action in a given state. Because of this, many learning algorithms instead learn the \textit{action value} of states. The action value of a state $S$ and action $A$ at time $t$ while the agent will follow a policy $\pi$ for all actions taken after time $t$ is denoted as follows:
\begin{equation}
    \label{eqn:action_value}
    q_\pi(S_t, A_t) = \mathbbm{E} \left[R_{t + 1} | S_t, A_t\right] + \gamma \mathbbm{E}_\pi \left[G_{t + 1} | S_t, A_t\right]
\end{equation}

One intuitive way to use action values is to modify our policy when the action value under our policy of the action the policy would take is less than the action value under our policy of some other action. When we do this its called \textit{policy iteration} and, in practice, it frequently converges to the optimal policy as long as there is no action in any state that we have a zero probability of selecting. If there is such an action, there's a chance that we could perhaps miss some rare but valuable reward. An easy way to prevent this is to pick the "best" action most of the time but take a random action on occasion. This method of picking actions is known as an \textit{$\epsilon$-greedy} policy, and many algorithms can compensate for it and learn the values of states or action values of state action pairs as if the agent were actually following a true greedy policy. One example of an algorithm that learns action values and can correct for an $\epsilon$-greedy policy is Q-learning. While many algorithms can compensate for an $\epsilon$-greedy policy, many other algorithms can compensate for the agent following some arbitrary policy while learning about some arbitrarily different policy.

Reinforcement Learning algorithms that learn about a different policy than the policy they use to pick actions are known as \textit{offpolicy} algorithms. These are especially important algorithms as it is often essential to be able to explore intelligently to learn about an environment rapidly and these algorithms allow complicated exploration behavior while still being able to formulate an optimal policy as the agent explores. However, while exploration is an important aspect for rapid learning, it is important to note that good exploration of the environment and a good learning algorithm alone are often not sufficient for learning to progress quickly in any Reinforcement Learning domain.

In addition to having algorithms that compensate for some deviation in the policy of the agent, we also have algorithms where the agent need not be provided with the true state of the environment but can instead provide some vector which describes the current state. This vector is known as a \textit{feature vector} and an example of an algorithm that can learn with feature vectors is, again, Q-learning. There are various methods to create a feature vector from the true state in a way that makes learning easier. However, the performance of most methods of these methods are heavily dependent on the domain. One simple example of such a method that works for cases where the state is described by a continuous-valued hyperplane is \textit{tile coding}. The general idea of tile coding is to reduce the dimensionality of a problem by overlaying the hyperplane with a series of oversized grids. Each grid has the same dimensionality as the hyperplane, but each subsequent grid is shifted slightly in relation to the previous grid. The indices of the cells over the grids of which a state falls in are then used to describe the state to the learning algorithm. The purpose of having multiple grids is so that states that are somewhat close to one another will appear in the same tile on some grids but different tiles in other ones. For more information on tile coding or any of the other previously mentioned details about Reinforcement Learning see \textit{Reinforcement learning - an introduction} by Sutton and Barto \cite{DBLP:books/lib/SuttonB98}.

Before we conclude this brief overview of Reinforcement Learning, there are a few small but important additional but advanced details about the Reinforcement Learning problem and the prior description of it that have so far been omitted for clarity but which we include here for completeness. Most notably, in Reinforcement Learning, we enforce the constraint on domains that they must retain the \textit{Markov Property}. That is, we require the following to hold in the domain:
\begin{equation}
    \label{eqn:markov_property}
    \text{P}\left(R_{t + 1}, S_{t + 1} | S_t, A_t, S_{t - 1}, A_{t - 1}, ...\right) = \text{P}\left(R_{t + 1}, S_{t + 1} | S_t, A_t\right)
\end{equation}

In other words the reward $R_{t + 1}$ and next state $S_{t + 1}$ is conditionally independent of all but the last state and action given the last state and action ($S_t$, $A_t$). Another interpretation of this is that knowing the full history of the interactions between the agent and environment does not give us any more relevant information we could use to predict the reward and next state than knowing only the last action taken and the last state. The enforcement of the Markov Property on the domain is the most significant detail that was omitted however there is one other important detail that was omitted.

Another detail that was previously omitted was that, in contrast to the Markov Property, it is not an explicit requirement of the Reinforcement Learning problem that timesteps be discrete. We do not handle the alternate case here however as most algorithms in Reinforcement Learning assume we are working with discrete timesteps.

\subsection{Local Outlier Factor}
\label{sec:local_outlier_factor}

Local Outlier Factors, or LOFs, are a metric used to find outliers in a dataset. First introduced by Breunig et al. \cite{DBLP:conf/sigmod/BreunigKNS00}, they estimate the density of the space around a data point and compare it to an equivalent estimate of the density of the space around nearby points. Comparing points to nearby points makes this a locality-based outlier metric and allows it to easily handle variable density clusters, unlike most global outlier metrics. To estimate the density of the space around a point, the LOF method simply calculates the average \textit{reachability distance} to its $k$ nearest neighbours ($k$-NN) where the reachability distance from a point $a$ to $b$ is simply the maximum of the distance between the points and the distance from point $b$ to the most distant point in its $k$-NN, or its \textit{$k$-distance}. The LOF of a data point is then just the ratio of the estimate of the density of the space around that data point, or the \textit{local reachability density} of that point, to the average local reachability density of each of that point's $k$-NN. We formalize this using the following set of equations:
\begin{align}
    \label{eqn:lof}
    &k\text{-distance}(p) = \underset{q \in k\text{NN}(p)}{\max} d(p, q) \\
    &\text{reach-dist}_k(p,q) = \max\{\text{d}(p,q), k\text{-distance}(q)\} \\
    &\text{lrd}(p) = \cfrac{1}{\frac{1}{k} \sum_{q \in k\text{NN}(p)} \text{reach-dist}_k(p, q)} \\
    &\text{LOF}(p) = \cfrac{\frac{1}{k} \sum_{q \in k\text{NN}(p)} \text{lrd}(q)}{\text{lrd}(p)}
\end{align}

Of crucial importance in the above equations is the fact that computing the LOF of a data point requires a combined total of $k + 1$ different $k$-NN searches. However, when computing the LOF for a data point, only the $k$-NN searches can be dependent on the number of data points in the dataset. This fact, along with the locality property of the LOF method, makes it suitable for data streams \cite{DBLP:conf/cidm/PokrajacLL07} which is the norm in Reinforcement Learning problems.

\end{document}


\section{Real data analysis}

\begin{frame}{Real networks studied in the paper}
    Real networks studied (directed, unweighted):
    \begin{itemize}
        \item \alert{Digg.com}: social bookmarking site
        \begin{itemize}
            \item Nodes: Digg users
            \item Edges: $a_{ij}=1 \Leftrightarrow$ ``$i$ is a follower of $j$''.
            \item $N = \num{190553}$; $L = \num{1552905}$
        \end{itemize}

        \item \alert{American Physical Society} (APS) articles and citation network
        \begin{itemize}
            \item Nodes: papers (from 1893 to 2009)
            \item Edges: $a_{ij}=1 \Leftrightarrow$ ``$i$ cites $j$''
            \item $N = \num{450056}$; $L = \num{4690967}$
        \end{itemize}
    \end{itemize}
    \vspace{1em}
    Estimator of node fitness: \alert{total relevance} of node $i$
    \[
        T_i = \sum_t r_i(t)
    \]
    To validate hypothesis of relevance and activity decay: measurement of \alert{empirical relevance} (see appendix).
\end{frame}

\begin{frame}{PageRank performance on real data}
    \begin{figure}
        \begin{columns}
            \column{0.55\textwidth}
                \includegraphics[width=1.1\textwidth]{figures/PageRank_realdata}
            \column{0.45\textwidth}
                \begin{footnotesize}
                    \begin{itemize}
                        \item \alert{Digg.com}: activity and relevance decay s.t. PageRank is maximally correlated with indegree in RM simulations with power-law decay.
                        \item \alert{APS}: \\ activity decays immediately, \\ relevance decays progressively.
                    \end{itemize}
                \end{footnotesize}
        \end{columns}
        \caption{Comparison of PageRank and indegree correlation with total relevance $T_i$ in real data. APS: PageRank strongly biased towards old nodes, because papers can only be cited by more recent papers.}
    \end{figure}
\end{frame}


\chapter{Introduction}

\faust (\textit{Functional Audio Stream}) is a functional programming language specifically designed for real-time signal processing and synthesis.  \faust targets high-performance signal processing applications and audio plug-ins for a variety of platforms and standards.

\section{Design Principles}

Various principles have guided the design of \faust :

\begin{itemize}

\item \faust is a \textit{specification language}. It aims at providing an adequate notation to describe \textit{signal processors} from a mathematical point of view. \faust is, as much as possible, free from implementation details.

\item \faust programs are fully compiled, not interpreted. The compiler translates \faust programs into equivalent C++ programs taking care of generating the most efficient code. The result can generally compete with, and sometimes even outperform, C++ code written by seasoned programmers.

\item The generated code works at the sample level. It is therefore suited to implement low-level DSP functions like recursive filters. Moreover the code can be easily embedded. It is self-contained and doesn't depend of any DSP library or runtime system. It has a very deterministic behavior and a constant memory footprint.

\item The semantic of \faust is simple and well defined. This is not just of academic interest. It allows the \faust compiler to be \emph{semantically driven}. Instead of compiling a program literally, it compiles the mathematical function it denotes. This feature is useful for example to promote components reuse while preserving optimal performance.

\item \faust is a textual language but nevertheless block-diagram oriented. It actually combines two approaches: \textit{functional programming} and \textit{algebraic block-diagrams}. The key idea is to view block-diagram construction as function composition. For that purpose, \faust relies on a \emph{block-diagram algebra} of five composition operations (\lstinline': , ~ <: :>').

\item Thanks to the notion of \textit{architecture}, \faust programs can be easily deployed on a large variety of audio platforms and plugin formats without any change to the \faust code.

\end{itemize}

\section{Signal Processor Semantic}
A \faust program describes a \emph{signal processor}.
The role of a \textit{signal processor} is to transforms a (possibly empty) group  of \emph{input signals} in order to produce a (possibly empty) group of \emph{output signals}.
Most audio equipments can be modeled as \emph{signal processors}.
They have audio inputs, audio outputs as well as control signals interfaced with sliders, knobs, vu-meters, etc.

More precisely :

\begin{itemize}

\item A \emph{signal} $s$ is a discrete function of time $s:\mathbb{Z}\rightarrow\mathbb{R}$.
\marginpar{\faust considers two type of signals: \emph{integer signals} ($s:\mathbb{Z}\rightarrow\mathbb{Z}$) and \emph{floating point signals} ($s:\mathbb{Z}\rightarrow\mathbb{Q}$) Exchanges with the outside world are, by convention, made using floating point signals. The full range is represented by sample values between -1.0 and +1.0.}
The value of a signal $s$ at time $t$ is written $s(t)$. The values of signals are usually needed starting from time $0$. But to take into account \emph{delay operations}, negative times are possible and are always mapped to zeros. Therefore for any \faust signal $s$ we have $\forall t<0, s(t)=0$. In operational terms this corresponds to assuming that all delay lines are signals initialized with $0$s.

\item The set of all possible  signals is $\mathbb{S}=\mathbb{Z}\rightarrow\mathbb{R}$.

\item A group of $n$ signals (a \emph{n}-tuple of signals) is written
$(s_{1},\ldots,s_{n})\in \mathbb{S}^{n}$.
The \emph{empty tuple}, single element of $\mathbb{S}^{0}$ is notated  $()$.

\item A \emph{signal processors} $p$, is a function from
\emph{n}-tuples of signals to \emph{m}-tuples of signals
$p:\mathbb{S}^{n}\rightarrow\mathbb{S}^{m}$. The set $\mathbb{P}=\bigcup_{n,m}\mathbb{S}^{n}\rightarrow\mathbb{S}^{m}$ is the
set of all possible signal processors.

\end{itemize}

As an example, let's express the semantic of the \faust primitive \lstinline'+'. Like any \faust expression, it is a signal processor. Its signature is $\mathbb{S}^{2}\rightarrow\mathbb{S}$. It takes two input signals $X_0$ and $X_1$ and produce an output signal $Y$ such that $Y(t) = X_0(t)+X_1(t)$.

Numbers are signal processors too. For example the number $3$ has signature  $\mathbb{S}^{0}\rightarrow\mathbb{S}$.  It takes no input signals and produce an output signal $Y$ such that $Y(t) = 3$.